I get a error whenever it's time to teleport players in my simple race game code. The error is "1 is not a valid member of Model" on line 15, which doesn't make much sense to me. Help?
local map = workspace:FindFirstChild("Map") local spawns = map:FindFirstChild("Spawns"):GetChildren() local finish = map:FindFirstChild("Finish") local h = Instance.new("Hint", workspace) while wait(1) do h.Text = "Starting race..." wait(3) h.Text = "Teleporting players..." for i, v in pairs(game.Players:GetPlayers()) do if v.Character.Humanoid.Health > 0 and v ~= nil then v.Character:MoveTo(spawns[i].Position) v.Character.Humanoid.WalkSpeed = 0 end end wait(3) for i = 3, 0, -1 do h.Text = i wait(1) end for i, v in pairs(game.Players:GetPlayers()) do if v.Character.Humanoid.Health > 0 and v ~= nil then v.Character.Humanoid.WalkSpeed = 16 end end h.Text = "Race in progress..." finish.Touched:wait() end
local map = workspace:FindFirstChild("Map") local spawns = map:FindFirstChild("Spawns"):GetChildren() local finish = map:FindFirstChild("Finish")
local h = Instance.new("Hint", workspace)
while wait(1) do h.Text = "Starting race..." wait(3)
h.Text = "Teleporting players..." for i, v in pairs(game.Players:GetPlayers()) do if v.Character.Humanoid.Health > 0 and v ~= nil then v.Character:MoveTo(spawns[i].Position) v.Character.Humanoid.WalkSpeed = 0 end end wait(3) for i = 3, 0, -1 do h.Text = i wait(1) end for i, v in pairs(game.Players:GetPlayers()) do if v.Character.Humanoid.Health > 0 and v ~= nil then v.Character.Humanoid.WalkSpeed = 16 end end h.Text = "Race in progress..." finish.Touched:wait()
end
I think I get what you are doing here. You are trying to warp each player to a respective spawn, right? If Each Spawn is labeled Spawns1, Spawns2, Spawns3, etc...
Delete the local variable "Spawns". Forget about that for now
for i, v in pairs(game.Players:GetPlayers()) do if v.Character.Humanoid.Health > 0 and v ~= nil then v.Character:MoveTo(map:FindFirstChild("Spawns"..i).Position) end end
So this should look for Spawns1, for player 1, Spawns2 for player 2, and so on.
This is a late post, so I didn't read the earlier comments. to make this work...
** make sure each Spawn is an individual part inside map**
Name each Spawn in ascending order "Spawns1" "Spawns2" etc...
delete the variable "Spawns"