So i'm making a machine that converts your resource to money at a tick rate of every second. The issue is that when the tick rate is 4 per second, and your starting amount is 30, you get -2. Now, to combat this, I made this script:
local plr = script.Parent.Parent.Parent.Parent if plr and plr:FindFirstChild("Owner") then plr = plr.Owner.Value end script.Parent.Changed:Connect(function(v) print("The change of amountHolding is: "..v) if script.Parent.Value < 0 then plr.leaderstats.Money.Value += math.abs(script.Parent.Value) script.Parent.Value = 0 end end)
I've tried everything. If you know why I get the error please answer
Answer explain more of your setup but looking at the script it might be line 10 the issue. becuase what are you referring to by doing script.Parent.Value = 0
also this script should be in serverscriptservice
Here's the issue why you get that error on line 1 you use plr
as an object of some sort not a player. local plr = script.Parent.Parent.Parent.Parent
Then on line 9 you use the plr
now as a player plr.leaderstats.Money.Value += math.abs(script.Parent.Value)
Try this instead
local Players = game:GetService('Players')--added player service local Player = Players.LocalPlayer--gets the player who activated the script local plr = script.Parent.Parent.Parent.Parent if plr and plr:FindFirstChild("Owner") then plr = plr.Owner.Value end script.Parent.Changed:Connect(function(v) print("The change of amountHolding is: "..v) if script.Parent.Value < 0 then Player.leaderstats.Money.Value += math.abs(script.Parent.Value)--Changed it to Player script.Parent.Value = 0 end end)
Hope this helps!!