So here's my code. It's for a spawner.
-- Locals
local team = script.Parent:WaitForChild("Team").Value
local root = script.Parent.Location:WaitForChild("HumanoidRootPart")
local root2 = script.Parent.Parent.Spawn2.Location:WaitForChild("HumanoidRootPart")
local team1 = game:GetService("Teams"):WaitForChild("Assault")
local team2 = game:GetService("Teams"):WaitForChild("Defend")
-- Setup
for _, v in pairs(script.Parent:GetDescendants()) do
if v:IsA("BasePart") then v.Anchored = true v.CanCollide = false end
end
for _, v in pairs(script.Parent.Location:GetDescendants()) do
if v:IsA("BasePart") then
v.Transparency = 1
v.CanCollide = false
v.Anchored = true
end
end
-- Main
game:GetService("Players").PlayerAdded:Connect(function(plr)
for i, v in pairs(game:GetService("Players"):GetChildren()) do
if i < 1 then
plr.Team = team1
elseif i > 1 then
plr.Team = team2
end
end
if plr.Team == team1 then
plr.Character:WaitForChild("HumanoidRootPart").CFrame = root.CFrame
elseif plr.Team == team2 then
plr.Character:WaitForChild("HumanoidRootPart").CFrame = root2.CFrame
end
end)
Please don't say "Use a spawnlocation" because i'm just testing this. So i keep getting this error: Workspace.Spawn.Script:31: attempt to index nil with 'WaitForChild' - Server - Script:31 How can i fix it?
