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!
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)
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)