I have a SpiderMan Physics game and when shooting my web onto floating blocks in the sky, it shoots multiple webs if I spam click. The debounce does not seem to work. I am wanting to have it to where you click and then it waits .5 seconds before you can click again
LocalScript
local Clicked = false Mouse.Button1Down:Connect(function() if Clicked == false and Mouse.Target ~= nil and Character:FindFirstChild('LeftHand') then -- when they click, local Pos = Mouse.Hit.p local Request = 'ShootWeb' ShootWeb:FireServer(Request,Pos) -- ..it shoots the web wait(.5) Clicked = true elseif Clicked == true then local Request = 'RemoveWeb' RemoveWeb:FireServer(Request) wait(.5) Clicked = false end end)
ServerScript
ShootWeb.OnServerEvent:Connect(function(Player,Request,MousePos) if Request == 'ShootWeb' then -- code below can be ignored local Part = Instance.new('Part',workspace.AttatchmentParts) Part.Name = Player.Name Part.Size = Vector3.new(1,1,1) Part.Transparency = 1 Part.Anchored = true Part.CanCollide = false Part.CFrame = CFrame.new(MousePos) local Att0 = Instance.new('Attachment',Player.Character.LeftHand) local Att1 = Instance.new('Attachment',Part) Rope = Instance.new('RopeConstraint',Player.Character.LeftHand) Rope.Color = BrickColor.new('Institutional white') Rope.Visible = true Rope.Length = (Player.Character.LeftHand.Position - Part.Position).magnitude Rope.Attachment0 = Att0 Rope.Attachment1 = Att1 end end)
Help would be greatly appreciated!
I would simply just add another variable in your local script. Maybe a variable called CanClick
Exmaple:
local Clicked = false local CanClick = true Mouse.Button1Down:Connect(function() if Clicked == false and Mouse.Target ~= nil and Character:FindFirstChild('LeftHand') and CanClick then CanClick = false Clicked = true local Pos = Mouse.Hit.p local Request = 'ShootWeb' ShootWeb:FireServer(Request,Pos) -- ..it shoots the web wait(.5) CanClick = true elseif Clicked == true and CanClick then CanClick = false Clicked = false local Request = 'RemoveWeb' RemoveWeb:FireServer(Request) wait(.5) CanClick = true end end)
Add the following into the local script Mouse.Button1Up:Connect(function() Clicked = falseend)