I’m new to coding so if I made really dumb mistakes, forgive me.
I’m trying to make a “Plates of Fate” type game with combat n stuff but the script I use doesn’t teleport all the players. Here’s the code,
while true do
repeat wait() until game.Players.NumPlayers >= 1
wait(2)
players = game.Players:GetPlayers()
i = 1
repeat
local Plate = game.ServerStorage.Cloud -- Change this to distinguish what the target block/model is.
local CPlate = Plate:Clone()
x = math.random(-256,256)
y = math.random(-10,10)
z = math.random(-256,256)
CPlate.Parent = game.Workspace
CPlate.Position = Vector3.new(x,y,z)
workspace:FindFirstChild(players[i].Name).Torso.CFrame = CFrame.new(x,y+2,z)
i = i+1
until i == #players + 1
end
On line 19, if you remove the + 1 it seems to be fine. I think it’s trying to find an extra player after the last one. You could alternatively use a for loop to loop through all players in the game:
for i, v in pairs(players) do
local Plate = game.ServerStorage.Cloud -- Change this to distinguish what the target block/model is.
local CPlate = Plate:Clone()
x = math.random(-256,256)
y = math.random(-10,10)
z = math.random(-256,256)
CPlate.Parent = game.Workspace
CPlate.Position = Vector3.new(x,y,z)
v.Character.Torso.CFrame = CFrame.new(x,y+2,z)
end
I also suggest you add a longer wait() at the top of your script to allow for all players to be in by the time the game starts and a delay after you teleport players so that they aren’t repeatedly teleported, unless that’s how your game is going to work.