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 » Scripting Helpers
Home Search
 

Re: Question about debounce.

Previous Thread :: Next Thread 
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
22 Apr 2013 02:13 PM
Does debounces make things only run once for whats between the debounces, like between false and true? the debounces
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
22 Apr 2013 02:16 PM
kinda

touched = false

part.Touched:connect(function(hit)
if not touched then
touched = true
print("TOUCHED")
wait(1)
touched = false
else
return
end
end)
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
22 Apr 2013 02:19 PM
Could i do this with the debounce to make this script give those two tools once, then it works again.Because it gives twice:

debounce = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.Lighting.G2A2:Clone().Parent = player.Backpack
game.Lighting.Sword:Clone().Parent = player.Backpack
end
end
end)

debounce = true
Report Abuse
StealthKing95 is not online. StealthKing95
Joined: 13 Dec 2008
Total Posts: 4263
22 Apr 2013 02:21 PM
touched = false
cooldown = 1

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
if touched then return end
touched = true
game.Lighting.G2A2:Clone().Parent = player.Backpack
game.Lighting.Sword:Clone().Parent = player.Backpack
wait(cooldown)
touched = false
end
end
end)
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
22 Apr 2013 02:35 PM
Why doesent this work then?:

debounce = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
game.Lighting.G2A2:Clone().Parent = player.Backpack
game.Lighting.Sword:Clone().Parent = player.Backpack
wait(5)
debounce = true
end
end
end)




I want it to take 5 seconds before i can touch it and make it work again....But it still gives twice
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
22 Apr 2013 02:52 PM
Debounce is a variable, not an official part. You have to set up a conditional statement to make it work, and inside that conditional make it toggle on at the beginning and back off when reactivating isn't undesired (normally that means at the end).

An example:

If debounce = false then
debounce = true
print("This message cannot be called again for five seconds.")
wait(5)
debounce = false
end
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
22 Apr 2013 03:03 PM
I wanna know why my script didnt work.
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
22 Apr 2013 03:10 PM
I was explaining that. It's because you're not checking your debounce variable in your conditional (you can use "if [insert conditional here] and debounce = true then"), so it goes on whether or not debounce is true.

As well as that, debounce is never set to false, which means that it's always true- every time the event is called, it will always be true no matter what. You'll want to place it at the beginning of your if statement to make it prevent repetition.
Report Abuse
UnBuild is not online. UnBuild
Joined: 22 Mar 2013
Total Posts: 3233
22 Apr 2013 03:11 PM
DoBounce = false
if DoBounce == false then
DoBounce = true
print("k")
wait(5)
DoBounce = false
end

Understand?
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
22 Apr 2013 03:12 PM
Why did stealth have 3 debounces?
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
22 Apr 2013 03:12 PM
Excuse me, I'm confusing myself a little here. It can NEVER go through if you set it to false at all times and checks for true, but it will only go through ONCE if you leave that debounce = true at the end. You'll need to decide whether debounce will be true or false while the if statement is going through.
Report Abuse
DaneelOlivaw is not online. DaneelOlivaw
Joined: 14 Apr 2012
Total Posts: 661
22 Apr 2013 03:14 PM
Because you have to start by defining what debounce is while it's not being used, then when the if goes through set it to the opposite of what the first debounce is, and at the end of the if statement set it back to the original status.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
22 Apr 2013 03:18 PM
Oh now i get it.Thanks.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 08:07 AM
But still, it doesent work:

debounce = false
script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if debounce == false and player then
debounce = true
game.Lighting.G3A4:Clone().Parent = player.Backpack
game.Lighting.Pistol:Clone().Parent = player.Backpack
wait(5)
debounce = false
end
end
end)
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 09:33 AM
Bump.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 10:25 AM
bump
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 10:31 AM
Check that the guns are named properly in the Lighting.

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
elseif hit.Parent.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
end
if debounce == false and player then
debounce = true
game.Lighting.G3A4:Clone().Parent = player.Backpack
game.Lighting.Pistol:Clone().Parent = player.Backpack
wait(5)
debounce = false
end

end)

That SHOULD work.

-={3137}=-
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 10:43 AM
No, just no.
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 10:44 AM
Oh and don't forget to put debounce =false on the top...

-={3137}=-
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 10:50 AM
I dont think you know how to script this, bump.
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 10:52 AM
debounce=false

script.Parent.Touched:connect(function(hit)
if hit.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
elseif hit.Parent.Parent:findFirstChild("Humanoid") then
player = game.Players:GetPlayerFromCharacter(hit.Parent.Parent)
end
if debounce == false and player then
debounce = true
game.Lighting.G3A4:Clone().Parent = player.Backpack
game.Lighting.Pistol:Clone().Parent = player.Backpack
wait(5)
debounce = false
end

end)

Worked fine for me. So it is absolutely a problem on your side.
I'll send a screenshot of it working if you need proof so bad.

-={3137}=-
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 10:54 AM
I dont think it will work since your trying to get workspace's character.
Report Abuse
Fedorakid is not online. Fedorakid
Joined: 17 Jul 2010
Total Posts: 7079
23 Apr 2013 10:55 AM
Which there isnt.

print(floodChecked())

>1
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 10:57 AM
That extra hit.Parent.Parent is in case you trip and your hat hits it. :D
You never know how important it maybe for your hat to press the button.
Plus if random part touches, it won't find anything anyway.

-={3137}=-
Report Abuse
eletrowiz is not online. eletrowiz
Joined: 08 Dec 2008
Total Posts: 12438
23 Apr 2013 10:57 AM
*may be

pew pew pew floodcheck.

-={3137}=-
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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