Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
|
| 17 Jan 2015 04:50 PM |
local on = 1 script.Parent.Touched:connect(function(hit) if on == 0 then return end on = 0 local h = hit.Parent:FindFirstChild("Humanoid") if h == nil then return end for p,v in pairs(script.Parent.Parent.Civilians:GetChildren()) do local player = game.Players:GetPlayerFromCharacter(hit.Parent) for i = 1,1 do script.Parent.SurfaceGui.TextLabel.Text = player.Character.Name.."'s Civilization." wait(5) script.Parent.SurfaceGui.TextLabel.Text = "Year 1 - Population: "..p end end wait(math.huge) on = 1 end)
-- No output |
|
|
| Report Abuse |
|
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
| |
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 17 Jan 2015 06:11 PM |
"local on = 1 script.Parent.Touched:connect(function(hit) if on == 0 then return end" is that your form of debounce?
local on = 1 script.Parent.Touched:connect(function(hit) if on == 1 then on = 0 -- script on = 1 end |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 06:16 PM |
Use a boolean for this.
local on = true
if(on)then on = false
--script
on = true end |
|
|
| Report Abuse |
|
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
|
| 17 Jan 2015 07:10 PM |
What's the difference between using numbers and booleans? Also, why is
local on = 1
if on == 0 then return on = 0
on = 1, not good? |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:18 PM |
booleans are always better than integers.
because it is simpler and cleaner, and cleaner scripts break less.
debounces are made usually with booleans, and i would recommend such. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:18 PM |
| it is easier for roblox to find if something is true or false, than to find if something is a specific integer. |
|
|
| Report Abuse |
|
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
|
| 17 Jan 2015 07:29 PM |
| Oh, okay. I'm so used to using numbers, but i'll switch to booleans. |
|
|
| Report Abuse |
|
|
|
| 17 Jan 2015 07:32 PM |
| The reason the debounce doesn't work is because it is set to 1 and is then checking if it's set to 0, so it will never run the script. |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 17 Jan 2015 07:40 PM |
local db = false
script.Parent.Touched:connect(function(hit) if db == false then db = true local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then for i,v in pairs(script.Parent.Parent.Civilians:GetChildren()) do coroutine.wrap(function() script.Parent.SurfaceGui.TextLabel.Text = plr.Name.."'s Civilization." wait(5) script.Parent.SurfaceGui.TextLabel.Text = "Year 1 - Population: "..i end)() end end db = false end) |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 17 Jan 2015 07:40 PM |
Lol soz I just realized what you're doing, use dis c:
local db = false
script.Parent.Touched:connect(function(hit) if db == false then db = true local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then for i,v in pairs(script.Parent.Parent.Civilians:GetChildren()) do script.Parent.SurfaceGui.TextLabel.Text = plr.Name.."'s Civilization." wait(5) script.Parent.SurfaceGui.TextLabel.Text = "Year 1 - Population: "..i end end db = false end) |
|
|
| Report Abuse |
|
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
|
| 17 Jan 2015 07:59 PM |
still doesn't work.
local on = true script.Parent.Touched:connect(function(hit) if (on) then on = false end local h = hit.Parent:FindFirstChild("Humanoid") if h == nil then return end for p,v in pairs(script.Parent.Parent.Civilians:GetChildren()) do local player = game.Players:GetPlayerFromCharacter(hit.Parent) for i = 1,1 do script.Parent.SurfaceGui.TextLabel.Text = player.Character.Name.."'s Civilization." wait(5) script.Parent.SurfaceGui.TextLabel.Text = "Year 1 - Population: "..p end end wait(math.huge) on = true end) |
|
|
| Report Abuse |
|
|
chimmihc
|
  |
| Joined: 01 Sep 2014 |
| Total Posts: 17143 |
|
|
| 17 Jan 2015 08:03 PM |
if on == false then on = true
-- not
if on then on = true
... |
|
|
| Report Abuse |
|
|
Goulstem
|
  |
| Joined: 04 Jul 2012 |
| Total Posts: 7177 |
|
|
| 17 Jan 2015 08:04 PM |
I forgot an end
local db = false
script.Parent.Touched:connect(function(hit) if db == false then db = true local plr = game.Players:GetPlayerFromCharacter(hit.Parent) if plr then for i,v in pairs(script.Parent.Parent.Civilians:GetChildren()) do script.Parent.SurfaceGui.TextLabel.Text = plr.Name.."'s Civilization." wait(5) script.Parent.SurfaceGui.TextLabel.Text = "Year 1 - Population: "..i end end db = false end end) |
|
|
| Report Abuse |
|
|
| |
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
|
| 17 Jan 2015 08:20 PM |
| It still resets the script when I touch the part. |
|
|
| Report Abuse |
|
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
| |
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
| |
|
Everment
|
  |
| Joined: 08 Oct 2009 |
| Total Posts: 6020 |
|
|
| 17 Jan 2015 10:57 PM |
"booleans are always better than integers." not when you're counting things.
"because it is simpler and cleaner, and cleaner scripts break less."
I'll agree with the first two (they're practically the same thing in this situation) but just because you use a bool instead of a number doesn't mean you change your chances of an error every time.
"debounces are made usually with booleans, and i would recommend such." True, and as would I.
"it is easier for roblox to find if something is true or false, than to find if something is a specific integer." I don't really know exactly what you said but I'm going to go off on a limb and so you're wrong.
---
As for op, your problem was when you went to wait `math.huge`, it never got to setting on back to 1. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 17 Jan 2015 11:03 PM |
| Everything Everment said plus that integers take up four bytes of data while booleans take up only one. Not that it's a big difference in your situation but it could make a difference if you're storing a big table or something. It could also make a difference if you're programming on a low resource machine, like a calculator. |
|
|
| Report Abuse |
|
|
Aj7Fish
|
  |
| Joined: 30 Dec 2014 |
| Total Posts: 500 |
|
|
| 18 Jan 2015 11:19 AM |
| It worked when I removed math.huge, but what do I replace it with if I don't want the loop to restart at all until the player leaves? |
|
|
| Report Abuse |
|
|