local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
coins.Value = 0
local points = Instance.new("IntValue",leaderstats)
points.Name = "Points"
local deaths = Instance.new("NumberValue",leaderstats)
deaths.Name = "Deaths"
deaths.Value = 0
local Status = game.ReplicatedStorage.Status
local inRound = game.ReplicatedStorage.inRound
if inRound == true then
player.Character.HumanoidRootPart.CFrame = game.Workspace.Spawn2.CFrame
else
player.Character.HumanoidRootPart.CFrame = game.Workspace.Spawn1.CFrame
end
It is giving me the error "ServerScriptService.leaderstats:25: attempt to index nil with ‘HumanoidRootPart’ "
It is referring to the last 5 lines where the if statement is called
even exists. PlayerAdded almost always fires before the players character is added. If you want to spawn a player at a spawn point make sure to do it after the character is spawned.
game.Players.PlayerAdded:Connect(function(player)
local leaderstats = Instance.new("Folder",player)
leaderstats.Name = "leaderstats"
local coins = Instance.new("IntValue",leaderstats)
coins.Name = "Coins"
coins.Value = 0
local points = Instance.new("IntValue",leaderstats)
points.Name = "Points"
local deaths = Instance.new("NumberValue",leaderstats)
deaths.Name = "Deaths"
deaths.Value = 0
player.CharacterAdded:Connect(function(char) ---this fires everytime the character of the player is added
local Status = game.ReplicatedStorage.Status
local inRound = game.ReplicatedStorage.inRound
if inRound == true then
char.HumanoidRootPart.CFrame = game.Workspace.Spawn2.CFrame
else
char.HumanoidRootPart.CFrame = game.Workspace.Spawn1.CFrame
end
end)
end)
guys just do
local Character = Player.Character or Player.CharacterAdded:Wait()
Player is the player and you can name it whatever you want as long as it is the same variable as the player you defined
also name Character whatever you want, name the variable not the “.Character” part