Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't my player teleporting?

Asked by 7 years ago

So, I'm making a racing game of 8 players, and I'm trying to test something to make a player teleports to a selected position. Like: Player 1 from the 8 players teleports to (0, 50 , 0) and Player 2 from the 8 players to (0, 100, 0) player 3 from 8 players to... the whole time until Player 8 has teleported to the selected position. But in my output stands: "Player1 is not a valid member of Workspace" (and other 7 too.) And here is my script:

if Wait(30) then
    game.Workspace.Player1.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 50, 0))

        game.Workspace.Player2.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 100, 0))

        game.Workspace.Player3.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 150, 0))

        game.Workspace.Player4.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 200, 0))

        game.Workspace.Player5.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 250, 0))

        game.Workspace.Player6.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 300, 0))

        game.Workspace.Player7.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 350, 0))

        game.Workspace.Player8.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, 400, 0))
end

I hope you can help me with this! Good luck!

-Gamer_io

0
Do you have all 8 players in Workspace, named Player1, Player2, etc? JJ_B 250 — 7y

1 answer

Log in to vote
2
Answered by
Nowaha 459 Moderation Voter
7 years ago

You should do it like this;

local plr = game:GetService("Players"):GetPlayers()
for i,v in pairs(plr) do
    v.Character.HumanoidRootPart.CFrame = CFrame.new(Vector3.new(0, i*50, 0)
end
0
This is basically it and a lot shorter than the original script wich would only work if all players were named player{1-8}. Just to make it simpler to understand I would rename i to iterator, v to player and plr to players. kazeks123 195 — 7y
0
PROVIDE EXPLANATION WITH YOUR ANSWERS. What did you change? Why did you change it? How does it help the asker? M39a9am3R 3210 — 7y
0
Nowaha, I don't wan't that all players teleport to 1 selected place, but that each player teleports to another place than others. like what I askd in quesion above. Thx to try to help... Gamer_io 14 — 7y
0
I'm sorry Nowaha, I whas wrong. It worked =D I probebley didn't knew how to use... Thx! Gamer_io 14 — 7y
0
I forgot to add an explaination, sorry ;p Nowaha 459 — 7y
Ad

Answer this question