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

How to prevent remote events firing multiple times?

Asked by 5 years ago

Once again, Remote Events have come to haunt me. The following is a local script from my egg launcher. Everything works fine except one issue. It launches two eggs at once which spawn on top of each other and get really wonky. I've confirmed that none of the scripts are running multiple times, the event just fires twice or more. I have no idea how I could control this in any way and from what I've seen on the forums, remote events are just horrendous to work with. Any help with why it's firing multiple times would be really appreciated

function fire()

    local vCharacter = Tool.Parent;
    local dir = HRT.CFrame.lookVector
    dir = computeDirection(dir)
    local pos = SpawnPart.Position + (SpawnPart.Position - HRT.Position)*2
    local EggY = HRT.Orientation.Y

    local missilePosition = pos
    local missileCFrame = CFrame.new(pos,  pos + dir)
    local missileOrientation = HRT.Orientation  

    if not debounce then
        debounce = true
        print("RanLocalFireFunction")
        fireEvent:FireServer(missileCFrame)
        debounce = false
    end
end
function computeDirection(vec)
    local lenSquared = vec.magnitude * vec.magnitude
    local invSqrt = 1 / math.sqrt(lenSquared)
    return Vector3.new(vec.x * invSqrt, vec.y * invSqrt, vec.z * invSqrt)
end

Tool.Enabled = true
function onActivated()
    wait(1)
    Tool.Enabled = false
    IsAttacking = true
    local character = Tool.Parent;
    local humanoid = character.Humanoid
    if humanoid == nil then
        print("Humanoid not found")
        return 
    end

    local targetPos = humanoid.TargetPoint
    fire()
    local yolkomaticTrack = YolkOMaticModel.AnimationController:LoadAnimation(yolkomaticani)
    yolkomaticTrack:Play()
    yolkomaticTrack.Looped = false
    wait(0.15)
    Tool.Enabled = true
end

Here is the script that responds to the firing.

Fired = game.ReplicatedStorage.YolkOMaticFireEvent.OnServerEvent:Connect(function(player, missileCFrame)
    Fired:Disconnect()
    --Launcher code that has no effect on the Remote Event issue
    --
    --
    --
end)
1
hmm, try adding a wait in that debounce if statment? since :FireServer is the one that activates first thats probarly where the problem is from starmaq 1290 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

As starmaq stated, add a wait(1) between line 16 and 17

0
Thanks for the response, however, I just realized my issue and it was a facepalm kind. I had the remote event in replicated storage, all I had to do was move it to the tool and now it only fires once. I'm not sure why this happens but I realize that thats how most Roblox tools work now. tygerupercut3 68 — 5y
0
you lucky man, if i only answerd without using comments xd starmaq 1290 — 5y
Ad

Answer this question