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

when sushi touches collector, gives error "attempt to index nil with FindFirstChild"?

Asked by 1 year ago

Heres the code in question:

local collector = workspace.SushiCollector
script.Parent.Touched:Connect(function(hit)
    if hit and hit.Parent and hit.Parent:FindFirstChild("SushiCollector") then
        local player = game.Players.LocalPlayer
        local leaderstats = player:FindFirstChild("leaderstats")
        if leaderstats then
            local MoneyValue = leaderstats:FindFirstChild("Money")
            if MoneyValue then  
                MoneyValue = MoneyValue + 5
                script.Parent:Destroy()
            end 
        end     
    end 
end)

1 answer

Log in to vote
0
Answered by 1 year ago
Edited 1 year ago

You can use LocalPlayer only in a LocalScripts.
Its giving you that error, because on the server the LocalPlayer value does not exist.
For this to work on server you would have to get the path to the player.

0
that fixed it for leaderstats, but moneyvalue still won't work. MrBucketOfficial 39 — 1y
0
yeah its still broken that did nothing MrBucketOfficial 39 — 1y
0
It does not work because to get the value of a value object you have to put `.Value` after it. ROMAHKAO 35 — 1y
Ad

Answer this question