The code below is a section of a bigger script, but this breaks sometimes but not all the time. It is a main scripts and is teleporting the players. However, on the bolded line the error pops up sometimes but not all the time. Can anyone spot an error! Thanks…
local redSpawn = mapChosenClone.RedSpawns:GetChildren()
local blueSpawn = mapChosenClone.BlueSpawns:GetChildren()
for i,v in pairs(game.Players:GetPlayers()) do
name = v.Name
check = game.Workspace:FindFirstChild(name)
if check then
local checkHumanoid = check:FindFirstChild(‘Humanoid’)
if check.Stats.Team.Value == ‘R’ and checkHumanoid then
check:MoveTo(redSpawn[i].Position)
elseif check.Stats.Team.Value == ‘B’ and checkHumanoid then check:MoveTo(blueSpawn[i].Position) --THIS LINE HERE
else
print(‘No team’)
end
end
end
If you’re getting a nil value, then that probably means there is something in that line that the system can’t find. If the 2 lines above works fine, with almost identical wording, I’d assume it has something to do with the actual variable. Check to see if “blueSpawn” exists at the location it needs to be in.
I’m not an expert, so I can’t actually fish out specific errors in code, but based on my assumptions there is probably something missing. Check your spelling too! That’s really important, Caps, everything.
local redSpawn = mapChosenClone.RedSpawns:GetChildren()
local blueSpawn = mapChosenClone.BlueSpawns:GetChildren()
local numRedSpawns = #redSpawn
local numBlueSpawns = #blueSpawn
local numRed = 0
local numBlue = 0
for i, v in pairs(game.Players:GetPlayers()) do
local char = v.Character
if char then
local tv = char:WaitForChild("Stats"):WaitForChild("Team").Value
if tv == "R" then
numRed = (numRed % numRedSpawns) + 1
char:WaitForChild("HumanoidRootPart").CFrame = redSpawn[numRed].CFrame
elseif tv == "B" then
numBlue = (numBlue % numBlueSpawns) + 1
char:WaitForChild("HumanoidRootPart").CFrame = blueSpawn[numBlue].CFrame
end
end
end
you are doing a function on a Character Model, which as what i remembers that does not have any PrimaryPart while :MoveTo() needs one. So instead you may wanna run a HumanoidRootPart check after Character