Hello, at one point in my game I need 1 player to be teleported to a specific position in the game. However, instead of one player, all players are being teleported and I am not sure why. The script is located in ServerScriptService. I have done a lot of research and cannot find an answer!.
Code:
while true do
wait(0.1)
if #game.Players:GetChildren() > 2 then
wait(0.1)
function teleAll(x, y, z)
local pos = Vector3.new(x, y, z)
for _, plr in pairs(game:GetService("Players"):GetPlayers(RandomPlayer())) do
if plr.Character then
plr.Character:MoveTo(pos)
end
end
end
function RandomPlayer()
local holdPlayers = {}
for _,v in pairs(game.Players:GetPlayers()) do
table.insert(holdPlayers, v.Name)
end
local randomNum = math.random(1, #holdPlayers)
local randomPlayerName = holdPlayers[randomNum]
local randomPlayer = game.Players:FindFirstChild(randomPlayerName)
if randomPlayer then
return randomPlayer
else
return
end
end
while true do
wait(0.1)
if game.Workspace.CaveTP.Value==1 then
wait(2)
teleAll(-1329.166, -102.418, -20.102)
script:Destroy()
end
end
end
end

2 comments
Thanks for helping me fix it! I owe you one ;)
No worries! :)