I’m using a ModuleScript named “PlayerManager” to spawn players to the map once the game has started. The problem occurs when attempting to relocate the player via CFrame, Position, or SetPrimaryPartCFrame().
It works for the most part when I test the game alone, however when I play with others I receive an error that the CFrame is nil. This 1 error causes the Game Loop to stop. It’s odd because I’m also checking to see if the Character even exists. As a workaround I’m able to set the player’s location with “player.RespawnLocation = whichSpawn” however the Player either spawns above the SpawnLocation (I changed Player CollisionGroup so players won’t spawn in Lobby which is directly above Map) or around it.
SpawnLocation sizes are 12,1,12 with no collisions and are anchored. I included all the lines I attempted already which can be determined by the Lua comments.
Here’s my code for the ModuleScript function that’s causing the issue, I used Roblox’s Battle Royale template to guide the setup of this code structure.
local function preparePlayer(player, whichSpawn) camOnEvent:FireAllClients() repeat wait() until player.Character -- wait for new character so no error local character = player.Character or player.CharacterAdded:wait() if character and player then for i,v in pairs(character:GetDescendants()) do if (v:IsA("BasePart")) then PhysicsService:SetPartCollisionGroup(v, playerGroup) end end wait() character:WaitForChild("HumanoidRootPart").CFrame = whichSpawn.CFrame + Vector3.new(0,10,0) --character.HumanoidRootPart.Position = whichSpawn.Position + Vector3.new(0,10,0) --character:SetPrimaryPartCFrame(whichSpawn.CFrame * CFrame.new(0, 10, 0)) --player.RespawnLocation = whichSpawn player:WaitForChild("PlayerGui").BackpackHotbar.Enabled = true player:WaitForChild("PlayerGui").BackpackHotbar.HotbarLogic.Disabled = false toolHandler(player, character) -- Because players will own different Bombs, each new bomb is saved after purchase local humanoid = character:WaitForChild("Humanoid") humanoid.Died:Connect(function() player:WaitForChild("PlayerGui").BackpackHotbar.Enabled = false player:WaitForChild("PlayerGui").BackpackHotbar.HotbarLogic.Disabled = true matchesGiver.giveMatch(player) -- Give Match/Round to Player removeActivePlayer(player) wait(5) -- Delay a little before respawning player respawnPlayerInLobby(player) end) else character = player.CharacterAdded:wait() end end
Thanks for the guidance, fairly new to creating games via Roblox yet experience in other engines. My mistake if this has been submitted in wrong forum thread.