Sell Pad not working

I am trying to make a sell pad for my friends simulator game.
It is in workspace with a script inside the sellpart.

The sell pad does not work could someone please explain why.

local sellPart = script.Parent

sellPart.Touched:Connect(function(hit)
	local leaderstats = hit.Parent:FindFirstChild("leaderstats")
	local ingots = leaderstats:FindFirstChild("Ingots")
	local cash = leaderstats:FindFirstChild("Cash")

	cash.Value = cash.Value + ingots.Value

	ingots.Value = 0
end)

any errors? did the touch event fire?

Does it throw an error?
Have you checked if the hit object is actually a humanoid character and not some random object?
Have you checked if the leaderstats in the character / player exist?

Yes,

Workspace.Sell.sellScript:5: attempt to index nil with 'FindFirstChild'  -  Server - sellScript:5

Yes, I do get an error.

Workspace.Sell.sellScript:5: attempt to index nil with 'FindFirstChild'  -  Server - sellScript:5

Leaderstats aren’t defined inside the character. I’m assuming you put them inside of the player for it to work.

local sellPart = script.Parent

sellPart.Touched:Connect(function(hit)
	local leaderstats = game.Players[hit.Parent.Name]:FindFirstChild("leaderstats")
	local ingots = leaderstats:FindFirstChild("Ingots")
	local cash = leaderstats:FindFirstChild("Cash")

	cash.Value = cash.Value + ingots.Value

	ingots.Value = 0
end)
1 Like

I’m pretty sure I understand that already. Leaderstats are never parented to the character.

Thank you for letting me know that the leaderstats were not defined! :slight_smile:

1 Like

I know, I was providing it as reference for Brodster.

1 Like

Oh! My apologiesssssssssssssssss.

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