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

Why does the server seems to fire several times?

Asked by 8 years ago

So these two scripts work together to fire a missile. Don't worry about the missing values. My problem is that more than one missile is fired when I press "w" once, and when they stack on top of each other they explode the cannon.

Local Script:

mouse.KeyDown:connect(function(key)
    if key == "w" and currentFighter.Seat:FindFirstChild("SeatWeld") and currentFighter.Seat.SeatWeld.Part1.Parent.Name == plr.Name then
        game:GetService("RunService").RenderStepped:connect(function()
        local mb = currentFighter.Body.BodyVelocity
        mb.Velocity = currentFighter.Body.CFrame.lookVector * 90
        end)
    end
end)

Server Script:

seat.ChildAdded:connect(function(plr)
    fe.OnServerEvent:connect(function(lplr, type)
    if type == 1 and seat and seat:FindFirstChild("SeatWeld") and seat.SeatWeld.Part1.Parent:FindFirstChild("Humanoid") then    
        p = Instance.new("Part")
        p.Name = "Missile"
        p.Parent = workspace
        p.CanCollide = true
        local m = Instance.new("SpecialMesh")
        m.MeshId = "http://roblox.com/asset/?id=2251534"
        m.Parent = p
        local spawnPos = body.Position + Vector3.new(0,-11,0)
        p.Position = spawnPos
        p.Rotation = body.Rotation
        p.Velocity = body.CFrame.lookVector * 1000
        local col = script.Collision:Clone()
        col.Parent = p 
        col.Disabled = false
            wait(.2)
        end
    end)
end)
0
I can't really say without the missing part of the script, I recommend adding it so the community has a better understanding of how to find a solution towards this problem. legosweat 334 — 8y
1
I would simply recommend a debounce. User#11440 120 — 8y

Answer this question