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 11 years ago

I mean, like :

01script.Parent.Touched:connect(function(hit)
02    if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
03        while ??? do
04            --Something
05        end
06    end
07end)
08 
09script.Parent.TouchEnded:connect(function(hit)
10    if game.Players:GetPlayerFromCharacter(hit.Parent) ~= nil then
11        --Do something that will cancel that upper while loop on line 4
12    end
13end)

Get it?

1 answer

Log in to vote
4
Answered by 11 years ago
01local touchTab = {}
02script.Parent.Touched:connect(function(hit)
03    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
04    if player then
05        touchTab[player] = true
06        while touchTab[player] do
07            --Something
08        end
09    end
10end)
11 
12script.Parent.TouchEnded:connect(function(hit)
13    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
14    if player then
15        touchTab[player] = nil
16    end
17end)
Ad

Answer this question