Attempt to index number with a leader stat

well not really a leaderstat but a folder named something else, anyway i am getting the error message of “attempt to index number with ‘Resources’”

here is the breaking script

wait()
local Stone = script.Parent.Metal
a = true

script.Parent.At.Break.Triggered:Connect(function(plr)
	
	if a and Stone.Value ~= 1 then
		a = false
	Stone.Value = Stone.Value - 1
		wait(1)
		a = true
	end
			
end)

script.Parent.Metal.Changed:Connect(function(plr)

		
		if Stone.Value == 1 then
		plr.Resources:Waitforchild("Metalp").Value += 1
		script.Parent.At.Break:Destroy()
		script.Parent.At.Collect:Destroy()
		script.Parent.Parent:Destroy()
		elseif Stone.Value == 3 then
			script.Parent.Parent.Thing.Transparency = 0.50
			script.Parent.Parent.Thing2.Transparency = 0.50
			script.Parent.Parent.Thing3.Transparency = 0.50
		elseif Stone.Value == 4 then
			script.Parent.Parent.Thing.Transparency = 0.25
			script.Parent.Parent.Thing2.Transparency = 0.25
			script.Parent.Parent.Thing3.Transparency = 0.25
		elseif Stone.Value == 5 then
			script.Parent.Parent.Thing.Transparency = 0
			script.Parent.Parent.Thing2.Transparency = 0
			script.Parent.Parent.Thing3.Transparency = 0
		elseif Stone.Value == 2 then
		script.Parent.Parent.Thing.Transparency = 0.75
		script.Parent.Parent.Thing2.Transparency = 0.75
		script.Parent.Parent.Thing3.Transparency = 0.75
	end
	
	
	
end)

Is “Metalp” wrote on purpose?
Try using plr:WaitForChild(“Resources”):Waitforchild(“Metalp”).Value += 1
If this doesn’t work can you send the line of the error? (Number)

yep metal p is on purpose, and the += gives me the same error

Is Metalp a NumberValue? If not make it a NumberValue.

oh yes it is an number value, i have a script for creating it

Try using :FindFirstChild(“Metalp”)

nope same thing, same error message

The parameter of the “.Changed” event of a “-Value” instance represents the new value of the “Value” property for that “-Value” instance not the player instance of which the value may have changed for.

That’s why the functions thinks the parameter “plr” (function variable) is a number value of 2.

You’ll need to find some other way to fetch the correct player instance.

1 Like

Thanks for mentioning that. I tried saying it earlier, in my code snippet though lol.

A “part” of the code snippet so people don’t need to click the link to see it:

script.Parent.Metal.Changed:Connect(function(value)
    if value > 0 then
        local transparency = 1 - (value/4)
        script.Parent.Parent.Thing.Transparency = transparency
        script.Parent.Parent.Thing2.Transparency = transparency
        script.Parent.Parent.Thing3.Transparency = transparency
    elseif value == 0 then
        -- .Changed doesn't pass the player who changed the value
        -- you'd need another method for giving the player's stats
        script.Parent:Destroy()
    end
end)

thanks! i will make it check if the number is already 1 on the breaking function