Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Ending an executed function in a different function?

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

✓ Accepted answer

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

2 comments

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.

0

updated post

This discussion is preserved as it was. New answers, comments, and votes are closed.