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

script that repeats itself without stopping ?

Asked by 5 years ago
Edited 5 years ago

hello

I have a very annoying little problem, actually I have a death animation (not finished) but actually if the brick that kills the player stays in contact with a member of the player, the script repeats itself without stopping, it's very annoying

server-side script

local Brick = script.Parent


local repstorage = game:GetService("ReplicatedStorage")

local Remote = repstorage:WaitForChild("RemoteKill")
--End--

--Code--
local function PlayerTouch(Part)

    local Parent = Parent Share
    if game.Players:GetPlayerFromCharacter(Parent) then
        Parent.Humanoid.Health = 0
        for i,v in pairs(game.Players:GetChildren()) do
        Remote:FireClient(v, v.Name)
end
    end
end

Brick.Touched:connect(PlayerTouched)


local script

-----------------------------------------------------------------------------------------------------------------


local repstorage = game:GetService("ReplicatedStorage")
local remoteKill = repstorage:WaitForChild("RemoteKill")
local sound = game:GetService("Players")


remoteKill.OnClientEvent:connect(function(playerName) --[[playerName is (v.Name) that you fired from server]]--
    sound = game.Players[playerName].PlayerGui.Sounds


sound.Chase:Stop()
sound.Killed:Play()
print(playerName..." has been killed by Sonic.EXE")


end)

Is there any way to make the OnTouch disabled?

0
Use a debounce titaneagle 0 — 5y

1 answer

Log in to vote
0
Answered by
gullet 471 Moderation Voter
5 years ago
Edited 5 years ago

There are two ways of limiting the connected function of the event, either you use a debounce that limits when the function can be called again, or you simply disconnect the connection as soon as it's used once.

Debounce

local debounce = false
Event:Connect(function()
    if not debounce then
        debounce = true -- blocks code from running again
        wait(5)
        debounce = false -- unblock and allows a new run
    end
end)

Disconnect

local connection = Event:Connect(function()
    connection:Disconnect() -- removes the connection after use
end)
Ad

Answer this question