Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Remote firing more than once?

Asked by
FiredDusk 1466 Moderation Voter
4 years ago
Edited 4 years ago

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!

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 IcyMizu 122 — 4y
0
The script is kinda messy, a lot of undefined variables. Maybe you can clear it up? d1_rek 46 — 4y
0
try placing a print on --code for shooting web o_fex 146 — 4y
0
Try placing the Clicked = true before the fire server. SethHeinzman 284 — 4y

2 answers

Log in to vote
1
Answered by 4 years ago

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)
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 :) FiredDusk 1466 — 4y
0
thought FiredDusk 1466 — 4y
0
Np! Glad it worked! Brandon1881 721 — 4y
Ad
Log in to vote
0
Answered by
d1_rek 46
4 years ago

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

0
I am still able to spam it and creates a lot of ropes FiredDusk 1466 — 4y
0
in other terms, the remote is firing multiple times FiredDusk 1466 — 4y
0
I thought you meant one click fired multiple times. Just create a debounce. d1_rek 46 — 4y

Answer this question