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

Error in my race script/code?

Asked by
R_alatch 394 Moderation Voter
8 years ago

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
0
Line e.e? Is it line 15? If so then 1 is not a member of the model spawns .-. i = 1 at that time of the loop Ryzox 220 — 8y
0
So how would I fix this? Also, the error is at line 15. R_alatch 394 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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

Ad
Log in to vote
0
Answered by 8 years ago

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"

Answer this question