I need a script to teleport one random player in coordinates -687.5,34.7,52.5
COMMUNITY QUESTION
script to teleport one random player?
1 answer
This is simple. You teleport players via:
player.Character:SetPrimaryPartCFrame(CFrame.new(-687.5,34.7,52.5))
The more complicated part is randomizing the players.
That would need a more complex script:
local function teleportRandom()
local players = game.Players:GetChildren() --All the players
local num = 0 --Number of counted players
local count = 0 --Current player being served
for _, player in ipairs(players) do --Counts all the players
num = num + 1
end
local rand = math.random (1, num) --Selects one random player
for _, item in ipairs(players) do --Tries to find selected player
count = count + 1
if rand == count then --Checks if player is the one
item:LoadCharacter() --Respawns the player
item.Character:SetPrimaryPartCFrame(CFrame.new(-687.5,34.7,52.5)) --Teleports player
end
end
end
2 comments
0
The script does not work, or I do something wrong. Have you tested the script?
0
No, i wrote this in a hurry, so its understandable if it doesn't work. I'll try to fix it when I have more time
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
BTW, shouldn't this be considered as a 'Not Constructive' question?