Need help with not being able to find a child

    script.Parent.Parent.Parent.Parent.Parent:WaitForChild("leaderstats"):WaitForChild("Stage").Value = 0
    local checkpointData = game.ServerStorage:FindFirstChild("CheckpointData")
    local userID = script.Parent.Parent.Parent.Parent.Parent.UserId
    checkpointData:FindFirstChild(userID)
    
end) ``` it says attempt to index nil with ‘findifrstchild’ any thing to help? When there is a child with that name

Is there an object in ServerStorage called CheckpointData?
FindFirstChild does not error if there isn’t, so that may be your problem.

Only on the server side and it’s in a local script is that the problem?

Yes, the client cannot access ServerStorage.
Move your object CheckpointData to ReplicatedStorage.

This post should have been added to your original post a few minutes ago:

Yea, it is because I now know what to put

Is there a way that it can still access serverstorage because it needs to be there for a script to work. So can I like use an event?

local player = script:FindFirstAncestorWhichIsA("Player")
local rs = game:GetService("ReplicatedStorage")
local CPD = rs:WaitForChild("CheckpointData")
local leaderstats = script:FindFirstAncestorWhichIsA("Folder")
local stageStat = leaderstats:WaitForChild("Stage")
stageStat.Value = 0
CPD:FindFirstChild(player.UserId)

Move “CheckpointData” to the ReplicatedStorage folder as that can be accessed by both local scripts and server scripts.

Yes, you will need to use a remote event or remote function.

I did that but the value in the script wasn’t set to 0 and here are both the local and the server scripts.

local RemoteEvent = RS.RemoteEvent

script.Parent.MouseButton1Click:Connect(function()
   script.Parent.Parent.Parent.Parent.Parent:WaitForChild("leaderstats"):WaitForChild("Stage").Value = 0
   local userID = script.Parent.Parent.Parent.Parent.Parent.UserId
   RemoteEvent:FireServer(userID)
end)

Local Script ^^^
Server Script:
local RS = game:GetService("ReplicatedStorage")
local Remote = RS.RemoteEvent

local CheckPointData = script.Parent:FindFirstChild("CheckpointData")

Remote.OnServerEvent:Connect(function(player, userID)
   CheckPointData:FindFirstChild(userID).Value = 0
end)

Also, I didn’t get any errors.

Can you help with the message above?

Put your script in ServerScriptService. Also, rewrite the script as follows:

local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local CheckPointData = game.ServerStorage:FindFirstChild("CheckpointData")

Remote.OnServerEvent:Connect(function(player)
   CheckPointData:FindFirstChild(player.userId).Value = 0
end)

It says attempt to index nil with ‘findfirstchild’ when the value is in there as you can see in the picture

I’ll just make a new checkpointsystem

Oh, I’m sorry! I just realized my mistake. Do this instead:

local Remote = game.ReplicatedStorage:WaitForChild("RemoteEvent")

local CheckPointData = game.ServerStorage:FindFirstChild("CheckpointData")

Remote.OnServerEvent:Connect(function(player)
   CheckPointData:FindFirstChild(tostring(player.userId)).Value = 0
end)

It still says the same error. It’s fine, I can still make a new one.

1 Like