Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Remote firing more than once?

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!

4 comments

0

well assuming u put the debounce local canshootweb = true right before the if statement it might just get back to true the whole time? test it with a print

0

The script is kinda messy, a lot of undefined variables. Maybe you can clear it up?

0

try placing a print on --code for shooting web

0

Try placing the Clicked = true before the fire server.

2 answers

✓ Accepted answer

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)

3 comments

0

Thank you very much. I just came back to scripting on roblox after 2 years. I should have though of this! Now the game is finished :)

0

thought

0

Np! Glad it worked!

Add the following into the local script Mouse.Button1Up:Connect(function() Clicked = falseend)

3 comments

0

I am still able to spam it and creates a lot of ropes

0

in other terms, the remote is firing multiple times

0

I thought you meant one click fired multiple times. Just create a debounce.

This discussion is preserved as it was. New answers, comments, and votes are closed.