Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

:SetPrimaryPartCFrame() not working on players character? [SOLVED]

this simple script is not working

game.Players.PlayerAdded:Connect(function(plr)
	local spawnpoints = game.Workspace.Lobby.SpawnPoints:GetChildren()
	local spawnamount = #game.Workspace.Lobby.SpawnPoints:GetChildren()
	local char = plr.Character
	char:SetPrimaryPartCFrame(spawnpoints[math.random(1,spawnamount)].CFrame)
end)

and its supposed to tp a player to a random spawnpoint heres the error i am getting:

ServerScriptService.Script:5: attempt to index nil with 'SetPrimaryPartCFrame'

Edit: fixed i just added a wait(1) after the first line i guess the character wasnt existing yet

1 comment

0

U also could of done WaitForChild("Humanoid")

1 answer

Try this on line 5

local char = player.Character or player.CharacterAdded:Wait()

1 comment

0

i just fixed it so i dont need help sorry but i think it would work since the problem was character didnt exist yet

This discussion is preserved as it was. New answers, comments, and votes are closed.