Problem with "arithmetic (mul) on nil and number"

I created a script that converts your statistics into money, but it doesn’t work and gives this error.

Script

local sellpad = script.Parent

local prices = {
	
	['Rock'] = 1,
	['Coal'] = 2,
	['Iron'] = 4,
	['Сopper'] = 6,
	['Gold'] = 15,
	['Platinum'] = 25,
	['Sapphire'] = 45,
	['Ruby'] = 65,
	['Emerald'] = 130,
	['Diamond'] = 250
}

local function sell(otherPart)
	local player = game.Players:FindFirstChild(otherPart.Parent.Name)
	if player then
		local amount = 0 
		for _, type in pairs(player.Stats:GetChildren()) do
			amount = amount + (prices[type.Name] * type.Value)
			type.Value = 0 
		end
		player.leaderstats.Money.Value = player.leaderstats.Money.Value + amount
	end
end

sellpad.Touched:Connect(sell)

I also tried adding the print command to find out where the error was and found out that the script does not see half of the statistics.

local amount = 0 
		for _, type in pairs(player.Stats:GetChildren()) do
			print(type) <-
			amount = amount + (prices[type.Name] * type.Value)
			type.Value = 0 

image
full stats here
image

Thank you.

Double check the names of the value instances, maybe there’s a whitespace before/after the name that you can’t see

For example, Copper’s name might actually be Copper with a space after it

1 Like

I’m apparently blind, thanks for solving the problem!

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