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: How to add debounce?

Previous Thread :: Next Thread 
Greyhound40 is not online. Greyhound40
Joined: 15 Oct 2008
Total Posts: 933
29 May 2014 02:03 AM
elseif key == "f" then
if Workspace:FindFirstChild(game.Players.LocalPlayer.Name..'Vehicle').Armed.Value == true then
for i,v in pairs(Workspace:FindFirstChild(game.Players.LocalPlayer.Name..'Vehicle').BodyKit:GetChildren()) do
wait()
if v.Name == "Gun" then
wait(0.1)
local sound = script.Parent.Blast:Clone()
sound.Parent = v
sound:Play()
local p = Instance.new("Part")
p.Name = "Projectile"
p.BrickColor = BrickColor.new("Institutional white")
p.Reflectance = 0
p.Transparency = 0
p.TopSurface = "Smooth"
p.BottomSurface = "Smooth"
p.Size = Vector3.new(1, 1, 1)
p.CanCollide = false
p.formFactor = "Symmetric"
local g = p:clone()
g.Parent = p
local w = Instance.new("Weld")
w.Parent = p
w.Part0 = p
w.Part1 = g
local mesh = script.Parent.LightMesh:clone()
mesh.Parent = p
local mesh = script.Parent.GlowMesh:clone()
mesh.Parent = g
local s = script.Parent["ProjectileScript"]:Clone()
s.Disabled = false
s.Parent = p

local bv = Instance.new('BodyVelocity',p)
wait()
bv.velocity = v.CFrame.lookVector*200
p.Parent=Workspace
p.CFrame = v.CFrame
wait()
sound:Remove()
end
end
else
print('I cannot fire the gunz!')
end


I want a person to only be able to fire the guns once every 0.3 seconds. I've added debounce in before, but it doesn't work! If anyone could add the debounce in then that would be appreciated, thank you. (For your information, this script works, so don't say it's a problem with the main code)
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
29 May 2014 02:07 AM
Debounce example
local Bounce = false
function onTouch()
if not Bounce then
Bounce = true

print("omg u touched me")

wait(5) --debounce time
Bounce = false
end
end
script.Parent.Touched:connect(onTouch)
Report Abuse
Greyhound40 is not online. Greyhound40
Joined: 15 Oct 2008
Total Posts: 933
29 May 2014 02:15 AM
I know how it works, but how do I add it to this script that I already have?
Report Abuse
Greyhound40 is not online. Greyhound40
Joined: 15 Oct 2008
Total Posts: 933
29 May 2014 02:16 AM
Because I've tried and it doesn't work.
Report Abuse
Greyhound40 is not online. Greyhound40
Joined: 15 Oct 2008
Total Posts: 933
29 May 2014 02:44 AM
Okay, fine. At least tell me where in the script I should define debounce.
Report Abuse
Distinctable is not online. Distinctable
Joined: 02 Mar 2010
Total Posts: 305
29 May 2014 02:56 AM
A debouce is simply a boolen (true or false value) that makes the script to where it will only run one time.

example.
while true do
game.Workspace.Example.Value+1 -- if this part of the script runs twice you need a debouce script.
wait()
end

example with debounce
Debounce = false

while true do
if Debounce == false then
debounce = true
game.Workspace.Example+1
wait()
end
end

Any further questions?
Report Abuse
Distinctable is not online. Distinctable
Joined: 02 Mar 2010
Total Posts: 305
29 May 2014 02:57 AM
while true do
if Debounce == false then
debounce = true
game.Workspace.Example+1
wait()
end
Debouce = true
end

I made a small error there.
Report Abuse
Paramedic4 is not online. Paramedic4
Joined: 23 Jan 2011
Total Posts: 5934
29 May 2014 03:16 AM
I think you have to define what Debounce is because the script reads it like nil
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