Attemp to index nil with FindFirstChild

on my script, i wrote plr.Character several times, but the Output gave me an error ONLY at line 5?!?!?!?!???!!

but my script, :

local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local CFrameDataStore = DSS:GetDataStore("CFrameDataStore")
	plr.Character:FindFirstChild("HumanoidRootPart").CFrame = CFrameDataStore:GetAsync(plr.UserId)

	CFrameDataStore:SetAsync(plr.UserId, plr.Character:FindFirstChild("HumanoidRootPart").CFrame)

	for i, plr in pairs(Players:GetPlayers()) do
		CFrameDataStore:SetAsync(plr.UserId, plr.chh:FindFirstChild("HumanoidRootPart").CFrame)CFrameDataStore:SetAsync(plr.UserId, plr.Character:FindFirstChild("HumanoidRootPart").CFrame)

where is the script and what type is it a local script or normal script??

it is a server script of course.

if you don’t know what is a serverscript then it is what you call a normal script.

noramal script and a serverscript are the same thing. just that it has 2 names.

1 Like

The problem is basically you don’t wait the character to loads

You need to use the CharacterAdded, if it doesn’t works try to use this other event

ok, if that was the problem then why only at line 5 output says?

1 Like

probably make a variable like
local char = plr.Character or CharacterAdded:Wait()

because the line 6 is the event connections so the problem is inside of this connection

1 Like

no it is line four???
what do you mean by line 6

line 6 is the end of the function

yes, so the problem is inside the connection thats the reason why the oput says it

The character is removed before the player, you need to hook a function to the .CharacterRemoving event instead.

When .PlayerRemoving fires the character has already been removed.

but the error is only at line 5…???

also does character remove fire everytime humanoid die or only when leave

You haven’t waited for the character to properly replicate before attempting to reference it.

local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
1 Like

yes, i did but did not work for me, and the output says that i forgot to enable the API Setting. i thought there was an error but let me turn it on and test the script

It still won’t work because you can’t save a CFrame value in datastores.

hmmnnnnnmm what can i do?
yeha what i can do

I wrote this script a few weeks ago which saves and loads a player’s character’s position.

it did not work at all anyways.

To save a CFrame in a datastore, add each value of the CFrame to a table, then save the table. Like so:

local cframe = plr.chh:FindFirstChild("HumanoidRootPart").CFrame
CFrameDataStore:SetAsync(plr.UserId, {cframe.X, cframe.Y, cframe.Z})

Let’s say the CFrame is 0, 0, 0. The table will be like this:

[1] = 0,
[2] = 0,
[3] = 0

but i not only wnat the opsiton but also rotation??

Then you can do the same thing, but with the rotation. Just switch some things out. Also, while loading the data, set each individual value, otherwise it will error. Like this:

local data = CFrameDataStore:GetAsync(plr.UserId)
plr.Character:FindFirstChild("HumanoidRootPart").CFrame.X = data[1]
plr.Character:FindFirstChild("HumanoidRootPart").CFrame.X = data[2]
plr.Character:FindFirstChild("HumanoidRootPart").CFrame.X = data[3]