1

# Attempt to index nil with 'leaderstats' Even though they exist?

wswswff 39
1 month ago

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
script.Parent.Value = 0
end
end)


I've tried everything. If you know why I get the error please answer

0
Change it in the script that subtracts from the leadervalue instead of making a new one specifically to handle this case. blowup999 659 — 1mo

0

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

0

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!!

0
thanks for trying but I still get the same error. It's okay if you can't find out why. No one is gonna notice an extra 2 bucks right? lol wswswff 39 — 1mo