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

How can I make a loop that will continue looping until you stop touching a part?

I mean, like :

script.Parent.Touched:connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
		while ??? do
			--Something
		end
	end
end)

script.Parent.TouchEnded:connect(function(hit)
	if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
		--Do something that will cancel that upper while loop on line 4
	end
end)

Get it?

1 answer

✓ Accepted answer
local touchTab = {}
script.Parent.Touched:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        touchTab[player] = true
        while touchTab[player] do
            --Something
        end
    end
end)

script.Parent.TouchEnded:connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent) 
    if player then
        touchTab[player] = nil
    end
end)

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