I've been scripting an RPG, and I thought that it might be an idea to store Player Stats in BoolValues and NumberValues inside the Player, and then edit them when the player Levels Up, or completed a Quest. The only problem is that the Values simply aren't being assigned. I'm not getting any Debug Errors, and the output doesn't tell me anything specific but "Gold is not a valid member of Player", "Gems is not a valid member of Player", "PlayerLevel is not a valid member of player", etc.
Here's my code:
--Player value Variables
Gold = Instance.new("NumberValue")
Gems = Instance.new("NumberValue")
PlayerLevel = Instance.new("NumberValue")
Exp = Instance.new("NumberValue")
HP = Instance.new("NumberValue")
Quest1 = Instance.new("BoolValue")
Quest2 = Instance.new("BoolValue")
Quest3 = Instance.new("BoolValue")
Quest4 = Instance.new("BoolValue")
Quest5 = Instance.new("BoolValue")
Player = game.Players.LocalPlayer
Gold.Value = 10
Gems.Value = 0
PlayerLevel.Value = 1
--Gui frame variables
ScreenGui = game.StarterGui.ScreenGui
ShopBG = ScreenGui.ShopBG
QuestsBG = ScreenGui.QuestsBG
StatsBG = ScreenGui.StatsBG
OptionsBG = ScreenGui.OptionsBG
--Start of functions
wait(3)
a = game.Players.LocalPlayer:GetChildren()
function assignValues() --assigns LocalPlayer all necessary values
repeat wait() until Player --waits until Player is loaded before assigning values
for i,v in pairs(a) do
if v:IsA("BoolValue" or "NumberValue") then --makes sure that the Player doesn't have values assigned already
Player.MaxHealth = Player.HP.Value
else --if they don't have values, then it assigns them values
Gold.Parent = Player
Gold.Name = "Gold"
Gems.Parent = Player
Gems.Name = "Gems"
PlayerLevel.Parent = Player
PlayerLevel.Name = "PlayerLevel"
Exp.Parent = Player
Exp.Name = "Exp"
HP.Parent = Player
HP.Name = "HP"
Quest1.Parent = Player
Quest1.Name = "Quest1"
Quest1.Value = false
Quest2.Parent = Player
Quest2.Name = "Quest2"
Quest2.Value = false
Quest3.Parent = Player
Quest3.Name = "Quest3"
Quest3.Value = false
Quest4.Parent = Player
Quest4.Name = "Quest4"
Quest4.Value = false
Quest5.Parent = Player
Quest5.Name = "Quest5"
Quest5.Value = false
end
end
end
game.Players.PlayerAdded:connect(assignValues)

4 comments
Sorry, I didn't realize I put the outdated script in. I changed it, it's now in a regular script, and I got rid of the part where I set the Gold and Gems variables to 10 and 0. I'll update it now.
Also, the reason I used a for loop and if statement was to make sure that values aren't assigned to ALL players when 1 player joins, only to the player who joined.
Thanks so much, it finally worked!
Np