This is because the script is attempting to find Money
in an instance that is nil
, which turns out to be leaderstats
. Try waiting for the player’s character or do game.Loaded:Wait()
at the top to see if it helps.
Another great trick, always set the attributes of an instance first before setting its parent, that way it’s more efficient.
-- Bad practice, setting parent before setting attributes meaning server has to connect and fire additonal events.
local Money = Instance.new("NumberValue",leaderstats)
Money.Name = "Money"
Money.Value = result.Money
-- Good practice, mitigates any unnecessary steps the server has to take.
local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Value = result.Money
Money.Parent = leaderstats