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

How do I make a loop that repeats?

Asked by 4 years ago

I want to make a script where if you touch this, it puts your name on a board. It only works once.

Script:

1game.Players.PlayerAdded:Connect(function(plr)
2    game.Workspace.NameMaker.Touched:Connect(function(hit)
3        local hum = hit.Parent:FindFirstChild("Humanoid")
4        if hum then
5        game.Workspace.MyFavPart.SurfaceGui.TextLabel.Text = plr.Name .. " Is cooler lol"
6        end
7    end)
8end)

Please help me. Thank you!

2 answers

Log in to vote
0
Answered by 4 years ago
1game.Workspace.NameMaker.Touched:Connect(function(hit)
2    local player = game.Players:GetPlayerFromCharacter(hit.Parent) --instead of getting player from the join event which only happens once until the player rejoins the game, you can get it from the character when it touches the part
3        local hum = hit.Parent:FindFirstChild("Humanoid")
4        if player and hum then
5            game.Workspace.MyFavPart.SurfaceGui.TextLabel.Text = plr.Name .. " Is cooler lol"
6    end
7end)
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

That a look at this article made by Roblox

You can use:

for, which I don't think it's what you want

1for i = 1, 10, 1 do
2    print("Hello, world!")
3end
4 
5-- Output: Hello, world! (x10)

while, which I think it's what you might want

1while wait() do -- you can also use while true do wait()
2    print("Hello, world!")
3end
4 
5-- Output: Hello, world! (xForever!)
6-- (Only stops if the value after while is false)

repeat until loops

1repeat
2    print("Hello, world!")
3until false
4 
5-- Output: Hello, world!
6--  (Only stops if the value after until is true. it is always executed at least once, even if it the condition is false)

Answer this question