Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

[UNSOLVED] Help with a Huge Script (2)?

So instead of editing my last thread, I just decided to put it into a new Question because I changed it so much. It still doesn't work, but it's a lot cleaner, and in two scripts now. So, if you didn't see the last thread, I'm trying to script an RPG game. I want it so that when a player connects, a function assigns a bunch of BoolValues and NumberValues to represent Experience, Levels, HP, etc. Whenever I test it, it gives me in the output "Gold is not a valid member of Player", "Gems is not a valid member of Player" etc, for each of the Values, and I'm not sure what I did wrong. Here's the code:

--THIS IS IN A REGULAR SCRIPT, NOT LOCALSCRIPT
--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 = 10
Gems = 0
PlayerLevel = 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"
	Gold.Value = 10
	Gems.Parent = Player
	Gems.Name = "Gems"
	Gems.Value = 0
	PlayerLevel.Parent = Player
	PlayerLevel.Name = "PlayerLevel"
	PlayerLevel.Value = 1
	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)

There is another script that assigns XP and Levels up the Player. I'm not sure if you need to see that too, but I'll include the code:

--THIS IS IN A LOCALSCRIPT
--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 = 10
Gems = 0
PlayerLevel = 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)


while true do
local xps = {0, 100, 300, 600, 1000, 1500, 2000, 2500, 3000, 4000, 5000, 6500, 8000, 9500, 11000, 12500, 14000, 15500, 18000, 21000, 25000, 30000, 35000, 40000, 45000, 50000, 57500, 65000, 72500, 82500, 100000};
local xp = Player.Exp.Value;
local level = 1;
while xps[level] and xps[level] <= xp do
    level = level + 1;
end

Player.HP.Value = 200 + 100 * Player.PlayerLevel.Value;

end

2 comments

0

What script is triggering the error? What line? Because there remains to be nothing which could trigger it in any of these scripts

0

I'm not getting anything in the output but "Gold is not a valid member of Player" for all of my Variables I set.

3 answers

The reason you're having issues is because you are rewriting the variables "Gold" and "Gems" as non-instances. This means that they are linked to the script and will not be found in the player.

In the script you have:

Gold = Instance.new("NumberValue")

and:

Gold = 10

therefore you are rewriting the same variable. In order to fix this problem;

Gold = Instance.new("NumberValue")
Gold.Value = 10

and then remove the line of code that sets its value to 10 after it is created.

You are also being repetitive, because you set the value of Gold twice in the script.

2 comments

0

While this is also a mistake in the script, it still wouldn't trigger the error he named

0

I changed it, though I still haev the same error. The script just isn't inserting the Values.

One reason is that in line 13 and 29 of script 1, you attempted to get the LocalPlayer which is only accessible from a Local Script. Looking at the second script, it seems it has the same problem on line 13. Change both of them to local scripts.

1 comment

0

I changed both of them to LocalScripts and I still have the same problem.

Since game.Players.LocalPlayer only works through local script, loop through all the player with a for loop instead, if you want to affect all the players.

for i,player in pairs(game.Players:GetPlayers()) do
print(player)
end

1 comment

0

I just changed it to a LocalScript. The values still aren't being assigned though.

This discussion is preserved as it was. New answers, comments, and votes are closed.