Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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.

3 comments

0

that fixed it for leaderstats, but moneyvalue still won't work.

0

yeah its still broken that did nothing

0

It does not work because to get the value of a value object you have to put .Value after it.

This discussion is preserved as it was. New answers, comments, and votes are closed.