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

How to Reconnect After a RBXScriptSignal:Connect() ?

Asked by 6 years ago

I'm trying to make a simple sword that disables a touch connection after it hits a player, but whenever I try this, it can only be fired once. Is there a way to do this?

For example:

local Blade = script.Parent.Blade

local Remote = Tool:WaitForChild("RemoteEvent")


Remote.OnServerEvent:Connect(function(player)--This fires when the client clicks their mouse.

Clicked = true

end)

function Slash(Hit)


if Clicked then


local Humanoid = Hit.Parent:FindFirstChild("Humanoid")

    if Humanoid then

        Humanoid:TakeDamage(20)

        Connection:Disconnect()

        Clicked = false

        end

    end

end

Connection = Blade.Touched:Connect(Slash)


1
You are better off using a debounce http://wiki.roblox.com/index.php?title=Debounce. User#5423 17 — 6y

Answer this question