generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Why doesn't Debounce work?

Previous Thread :: Next Thread 
Aj7Fish is not online. 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 is not online. Aj7Fish
Joined: 30 Dec 2014
Total Posts: 500
17 Jan 2015 05:38 PM
bump
Report Abuse
chimmihc is not online. 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
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
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 is not online. 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
DoAndDoOver is not online. DoAndDoOver
Joined: 06 Sep 2014
Total Posts: 628
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
DoAndDoOver is not online. DoAndDoOver
Joined: 06 Sep 2014
Total Posts: 628
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 is not online. 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
vortexyamum is not online. vortexyamum
Joined: 31 Aug 2011
Total Posts: 1979
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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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
ByteScetch is not online. ByteScetch
Joined: 24 Jun 2012
Total Posts: 1984
17 Jan 2015 08:12 PM
Bcuz the booty is tyt
Report Abuse
Aj7Fish is not online. 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 is not online. Aj7Fish
Joined: 30 Dec 2014
Total Posts: 500
17 Jan 2015 09:27 PM
bump
Report Abuse
Aj7Fish is not online. Aj7Fish
Joined: 30 Dec 2014
Total Posts: 500
17 Jan 2015 10:20 PM
bump(x2)
Report Abuse
Everment is not online. 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 is not online. 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 is not online. 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
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image