Attempt to index nil with 'HumanoidRootPart'

Im trying to save data but the game is thinking my humanoid root part is nil when im still ingame

game.ReplicatedStorage.Remotes.DespawnCharacter.OnServerEvent:Connect(function(player)
	warn(player.Parent)
	
	
	local Character = player.Character

	
	local ConvertedThing = Instance.new("StringValue")
	ConvertedThing.Value = character.HumanoidRootPart.CFrame.X,character.HumanoidRootPart.CFrame.Y,character.HumanoidRootPart.CFrame.Z
	print(ConvertedThing.Value)

The line that causes this issue is

	ConvertedThing.Value = character.HumanoidRootPart.CFrame.X,character.HumanoidRootPart.CFrame.Y,character.HumanoidRootPart.CFrame.Z

Its because the HumanoidRootPart has not loaded in yet. This post here should help you fix your problem.

For people who are lazy:

local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

This solution works because it uses ternary operators in order to get the character. It notices that Player.Character is nil, so it uses the right-hand assignment instead which waits for the character.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.