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 3 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:

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

Please help me. Thank you!

2 answers

Log in to vote
0
Answered by 3 years ago
game.Workspace.NameMaker.Touched:Connect(function(hit)
    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
        local hum = hit.Parent:FindFirstChild("Humanoid")
        if player and hum then
            game.Workspace.MyFavPart.SurfaceGui.TextLabel.Text = plr.Name .. " Is cooler lol"
    end
end)
Ad
Log in to vote
0
Answered by 3 years ago
Edited 3 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

for i = 1, 10, 1 do
    print("Hello, world!")
end

-- Output: Hello, world! (x10)

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

while wait() do -- you can also use while true do wait()
    print("Hello, world!")
end

-- Output: Hello, world! (xForever!)
-- (Only stops if the value after while is false)

repeat until loops

repeat
    print("Hello, world!")
until false

-- Output: Hello, world! 
--  (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