Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited by JesseSong 3 years ago

This question has been solved by the original poster.

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

0
U also could of done WaitForChild("Humanoid") no0bgaming748 24 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Try this on line 5

local char = player.Character or player.CharacterAdded:Wait()
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 TFlanigan 86 — 3y
Ad

Answer this question