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

Why is my remote event being detected multiple times?

Asked by 3 years ago
local explosion = nil
local tool = script.Parent
local DuplicatePrevention = {}
local player = tool.Parent.Parent
script.Parent.Activated:Connect(function(Activated)
    game.ReplicatedStorage.RemoteEvent:FireClient(player)
    print("Fired Client")
    Activated = nil
    game.ReplicatedStorage.ILikeBEaNs.OnServerEvent:Connect(function(plr, target)
        print("Client Returned")
        if plr == player then
            if player.Character:FindFirstChild("Humanoid") then
                if player.Character.Humanoid.Health > 0 then
                    print(target)
                    if target and target.Parent and target.Parent:FindFirstChild("Humanoid") then
                        target.Parent.Humanoid.Health = 0
                    end
                    plr = nil
                    target = nil
                end
            end
        end
    end)
end)

This is my code. Everything is working fine, but it prints "Client returned" multiple times. The code is returning 1 the first time. 2 the second time, 3 the third time, 4 the fourth time, so on. 16:35:29.154 Fired Client - Server - Script:7

16:35:29.239 Client Created Value - Client - LocalScript:6

16:35:29.239 Client Fired Event - Client - LocalScript:8

16:35:29.254 Client Returned - Server - Script:10 -- the first time

16:35:29.254 Baseplate - Server - Script:14

16:35:29.255 Client Returned - Server - Script:10 -- this is the second click so it returned again

16:35:29.255 Baseplate - Server - Script:14

Any idea why this happens?

0
oops forgot the localscript Qwertoony 70 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

use deactivate function when it becomes activated!

0
Thank you for the answer :D I figured it out using a debounce but this also works, I completely for got that. THX :DDD Qwertoony 70 — 3y
Ad

Answer this question