Index Nil error with leaderstats

Hello, I am trying to practice scripting by creating a simple tycoon.
I am having issues with a furnace not rewarding the player cash upon smelting the ore. I have tried several things. This is the script:

local Furnace = script.Parent
function Smelt(hit)
	if hit.Name == "Ore1" then
		local owner = Furnace.Parent.TycoonOwner.Value
		if owner then
			local money = owner.leaderstats.Money
			money.Value = money.Value + 1
		print("Incorrect Substance smelted")


The output log shows that it is attempting to index nil with Money on line 6.
local money = owner.leaderstats.Money

Studio file if you should need it

BaseplateIssue.rbxl (31.5 KB)

What is failing?

Hello, is the owner variable the name of the player?

You can use :FindFirstChild to find the player. Because it won’t work because you are trying to get the leaderstats of a name.

local owner = game:GetService("Players"):FindFirstChild(Furnace.Parent.TycoonOwner.Value)
1 Like

Yes, the owner value is the name of the character.

This worked, thank you very much.