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

Ending an executed function in a different function?

Asked by 8 years ago

Let's say I did (extremely bleak below):

function onChatted38(message,player)

if message=="loopkill" and Admin[player.Name] then

while true do

wait()

player.Character:BreakJoints()

How could I, using a new seperate function, end the loopkill?

Any help appreciated.

I ask because in Person299's admin commands he uses something similar, but I don't understand how he did it, and I want my commands to be my own and not some copy and paste.

1 answer

Log in to vote
2
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

Stop the loop from somewhere else.

local condition=true
function Loop()
    while condition do
        wait()
        print("loop")
    end
end

function OtherFunction()
    condition=false
end

In the case of a loopkill program, it would actually be best to connect to CharacterAdded instead of repeatedly and redundantly killing the dead character.

Based on what you posted

local loopkill={}
function onChatted38(message,player)
    if message=="loopkill" and Admin[player.Name] then
        loopkill[player.Name]=true
        while loopkill[player.Name]do
            wait()
            player.Character:BreakJoints()
        end
    elseif message=="unloopkill"and Admin[player.Name]then
        loopkill[player.Name]=nil
    end
end

Using CharacterAdded

local loopkill={}
function onChatted38(message,player)
    if Admin[player.Name]then
        if message=="loopkill"then
            loopkill[player.Name]=player.CharacterAdded:connect(function(character)
                character:BreakJoints()
            end)
            player.Character:BreakJoints()
        elseif message=="unloopkill"and loopkill[player.Name]then
            loopkill[player.Name]:disconnect()
        end
    end
end
0
It said something about a nil value. Could you implement it into the code given please? Sorry, this is a fairly new area of scripting for me. Huminoidjoe 20 — 8y
0
updated post 1waffle1 2908 — 8y
Ad

Answer this question