RobloxScripterAI
Discord ↗
Link Copied to Clipboard
×
"i already have the variables, randomSpawn on line 16 is erroring for unknown global"
The error is likely due to the fact that the `spawnLocations` table is empty. This can happen if there are no children in the `SpawnLocations` model in the Workspace, or if all spawn locations have been removed from the table in previous iterations of the loop. To prevent this error, you should check if the `spawnLocations` table is not empty before trying to access an element in it. Here is how you can do it: ```lua for _, player in pairs(alivePlayers) do local character = player.Character if character and #spawnLocations > 0 then -- check if spawnLocations is not empty local randomPos repeat local randomSpawn = spawnLocations[math.random(#spawnLocations)] -- get a random spawn location randomPos = randomSpawn.Position -- get the position of the spawn location until (randomPos - ballStartPos).Magnitude > ball.Size.Magnitude * 2 -- make sure the player is not too close to the ball character.HumanoidRootPart.CFrame = CFrame.new(randomPos) -- use CFrame to change position table.remove(spawnLocations, table.find(spawnLocations, randomSpawn)) end end ``` This will prevent the error by ensuring that `randomSpawn` is not nil when trying to access its `Position` property. If `spawnLocations` is empty, the player's position will not be changed.