This script picks a random player and then teleports them to the place but if the script finds no players the script deletes itself and prints No Players but then I added a while true do and I tested it but now it always says No Players even when there is a player. Can anyone help me?
Here is the script I used
local Players = game.Players
local player = Players:GetChildren()
while true do
wait(5)
if #player == 0 then
print("No players.")
script:Destroy()
return
end
local pickedPl = player[math.random(1, #player)]
wait()
pickedPl.Character.Torso.CFrame = CFrame.new(109.5, 25.5, -95.5)
print(pickedPl.Name)
end

8 comments
It’s script:Destroy(), not script:remove()
It’s script:Destroy(), not script:remove()
You need a wait before the end
even with the wait it still does not work
@SBlankthorn, you don't really have to do that. while loops don't crash as long as you have some type of delay. The delay is 5 seconds. The asker does not need another wait()
im confused on what im doing wrong
The indents are maybe confusing the script. Try removing an indent on your "if #player == 0 then" statement. Hopefully that works!
OH YEAH! If you're removing an indent on the if statement remove an indent on the "end" on line 10 as well.