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:
01 | local plr = script.Parent.Parent.Parent.Parent |
02 | if plr and plr:FindFirstChild( "Owner" ) then |
03 | plr = plr.Owner.Value |
04 | end |
05 |
06 | script.Parent.Changed:Connect( function (v) |
07 | print ( "The change of amountHolding is: " ..v) |
08 | if script.Parent.Value < 0 then |
09 | plr.leaderstats.Money.Value + = math.abs(script.Parent.Value) |
10 | script.Parent.Value = 0 |
11 | end |
12 | 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
01 | local Players = game:GetService( 'Players' ) --added player service |
02 | local Player = Players.LocalPlayer --gets the player who activated the script |
03 | local plr = script.Parent.Parent.Parent.Parent |
04 | if plr and plr:FindFirstChild( "Owner" ) then |
05 | plr = plr.Owner.Value |
06 | end |
07 |
08 | script.Parent.Changed:Connect( function (v) |
09 | print ( "The change of amountHolding is: " ..v) |
10 | if script.Parent.Value < 0 then |
11 | Player.leaderstats.Money.Value + = math.abs(script.Parent.Value) --Changed it to Player |
12 | script.Parent.Value = 0 |
13 | end |
14 | end ) |
Hope this helps!!