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

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

Asked by 10 years ago

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

Log in to vote
4
Answered by 10 years ago
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)
Ad

Answer this question