Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 10 years ago

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:

01--THIS IS IN A REGULAR SCRIPT, NOT LOCALSCRIPT
02--Player value Variables
03Gold = Instance.new("NumberValue")
04Gems = Instance.new("NumberValue")
05PlayerLevel = Instance.new("NumberValue")
06Exp = Instance.new("NumberValue")
07HP = Instance.new("NumberValue")
08Quest1 = Instance.new("BoolValue")
09Quest2 = Instance.new("BoolValue")
10Quest3 = Instance.new("BoolValue")
11Quest4 = Instance.new("BoolValue")
12Quest5 = Instance.new("BoolValue")
13Player = game.Players.LocalPlayer
14Gold = 10
15Gems = 0
View all 72 lines...

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:

01--THIS IS IN A LOCALSCRIPT
02--Player value Variables
03Gold = Instance.new("NumberValue")
04Gems = Instance.new("NumberValue")
05PlayerLevel = Instance.new("NumberValue")
06Exp = Instance.new("NumberValue")
07HP = Instance.new("NumberValue")
08Quest1 = Instance.new("BoolValue")
09Quest2 = Instance.new("BoolValue")
10Quest3 = Instance.new("BoolValue")
11Quest4 = Instance.new("BoolValue")
12Quest5 = Instance.new("BoolValue")
13Player = game.Players.LocalPlayer
14Gold = 10
15Gems = 0
View all 39 lines...
0
What script is triggering the error? What line? Because there remains to be nothing which could trigger it in any of these scripts BlueTaslem 18071 — 10y
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. SlickPwner 534 — 10y

3 answers

Log in to vote
3
Answered by
RedCombee 585 Moderation Voter
10 years ago

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:

1Gold = Instance.new("NumberValue")

and:

1Gold = 10

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

1Gold = Instance.new("NumberValue")
2Gold.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.

0
While this is also a mistake in the script, it still wouldn't trigger the error he named BlueTaslem 18071 — 10y
0
I changed it, though I still haev the same error. The script just isn't inserting the Values. SlickPwner 534 — 10y
Ad
Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

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.

0
I changed both of them to LocalScripts and I still have the same problem. SlickPwner 534 — 10y
Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

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.

1for i,player in pairs(game.Players:GetPlayers()) do
2print(player)
3end
0
I just changed it to a LocalScript. The values still aren't being assigned though. SlickPwner 534 — 10y

Answer this question