Hi, I'm new to scripting and are trying to make a mining game. Here is my script, whenever I try to hit the ore this error appears "8:attempt to perform arithmetic (sub) on userdata and number"
local Ore = game.Workspace.Ore.Gold.GoldOre local Pick = game.StarterPack.Pic local Health = game.Workspace.Ore.Gold.GoldOre.Health Ore.Touched:Connect(function(hit) if hit.Parent.Name == "Pic" then Health = Health - 10 if Health == 0 then Health = 30 Ore.Transparency = 1 Ore.CanCollide = false wait(5) Ore.Transparency = 0 Ore.CanCollide = true end end end)
Thanks - WhoopsILied
From the looks of things Health
is a value holder which would explain your error.
To resolve this you want to access to value indise of Health e.g. Health.Value
local Ore = game.Workspace.Ore.Gold.GoldOre local Pick = game.StarterPack.Pic local Health = Ore.Health -- health is inside ore so just reuse the variable Ore.Touched:Connect(function(hit) if hit.Parent.Name == "Pic" then -- you could also check the health here. Health.Value = Health.Value - 10 -- use <= as multiple touched events may result in a nagative if Health.Value <= 0 then Health.Value = 30 Ore.Transparency = 1 Ore.CanCollide = false wait(5) Ore.Transparency = 0 Ore.CanCollide = true -- should the health be reset here as well? end end end)
I am unsure why you need to hold health in a value object. You should be ok having a local veriable for the health.
I hope this helps. Please comment ig you have any other questions about this post.