I'm rescripting a value assigner for an RPG game, and for some reason it just doesn't want to work. The output gives me: leaderstats is not a valid member of Player gold is not a valid member of Player etc.
Code:
plr = game.Players.LocalPlayer leaderstats = Instance.new("IntValue") gold = Instance.new("NumberValue") gems = Instance.new("NumberValue") level = Instance.new("NumberValue") xp = Instance.new("NumberValue") goldKey = "PlayerGold" gemsKey = "PlayerGems" levelKey = "PlayerLevel" xpKey = "PlayerExp" function assignValues() repeat wait() until plr --leaderstats leaderstats.Parent = plr leaderstats.Name = "leaderstats" repeat wait() until leaderstats --gold and gems gold.Parent = plr.leaderstats gold.Name = "Gold" gold.Value = plr:LoadNumber(goldKey) or 10 gems.Parent = plr.leaderstats gems.Name = "Gems" gems.Value = plr:LoadNumber(gemsKey) --level and xp level.Parent = plr.leaderstats level.Name = "Level" level.Value = plr:LoadNumber(levelKey) or 1 xp.Parent = plr xp.Name = "Exp" xp.Value = plr:LoadNumber(xpKey) end function saveStats() repeat wait() until plr --gold and gems save plr:SaveNumber(goldKey, plr.leaderstats.Gold.Value) plr:SaveNumber(gemsKey, plr.leaderstats.Gems.Value) --level and xp save plr:SaveNumber(levelKey, plr.leaderstats.Level.Value) plr:SaveNumber(xpKey, plr.Exp.Value) end game.Players.PlayerAdded:connect(assignValues) plr.leaderstats.Gold.Changed:connect(saveStats) plr.leaderstats.Gems.Changed:connect(saveStats) plr.leaderstats.Level.Changed:connect(saveStats) plr.Exp.Changed:connect(saveStats)
put the instance.new parts inside the function
wait(2) -- wait for the character to load goldKey = "PlayerGold" gemsKey = "PlayerGems" levelKey = "PlayerLevel" xpKey = "PlayerExp" function assignValues() plr = game.Players.LocalPlayer leaderstats = Instance.new("IntValue") gold = Instance.new("NumberValue") gems = Instance.new("NumberValue") level = Instance.new("NumberValue") xp = Instance.new("NumberValue") --leaderstats leaderstats.Parent = plr leaderstats.Name = "leaderstats" --gold and gems gold.Parent = plr.leaderstats gold.Name = "Gold" gold.Value = plr:LoadNumber(goldKey) or 10 gems.Parent = plr.leaderstats gems.Name = "Gems" gems.Value = plr:LoadNumber(gemsKey) --level and xp level.Parent = plr.leaderstats level.Name = "Level" level.Value = plr:LoadNumber(levelKey) or 1 xp.Parent = plr xp.Name = "Exp" xp.Value = plr:LoadNumber(xpKey) end function saveStats() repeat wait() until plr --gold and gems save plr:SaveNumber(goldKey, plr.leaderstats.Gold.Value) plr:SaveNumber(gemsKey, plr.leaderstats.Gems.Value) --level and xp save plr:SaveNumber(levelKey, plr.leaderstats.Level.Value) plr:SaveNumber(xpKey, plr.Exp.Value) end assignValues() plr.leaderstats.Gold.Changed:connect(saveStats) plr.leaderstats.Gems.Changed:connect(saveStats) plr.leaderstats.Level.Changed:connect(saveStats) plr.Exp.Changed:connect(saveStats)
i hope ur RPG is good :)