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

Role is not a valid member of PlayerGui?

Asked by
Nep_Ryker 131
4 years ago
Edited 4 years ago

So currently I made a script in ServerScriptService and it will change a NumberValue inside a player's PlayerGui, said NumberValue is inside a Gui called "Role".

But I keep getting an error saying that Role is not a valid member of PlayerGui.

I've tried doing :WaitForChild() as well but then I get a message saying that an infinite yield is possible.

This is basically it that I did:

local random = players[randomPlayer].PlayerGui.Role.ROLE

I am choosing a random player and then I am trying to change something inside their PlayerGui, but for some apparent reason the Gui isn't a valid member. I've checked it on the Explorer when in-game and it's also there. If someone knows why, please help. Thanks.

You can look at the GUI's structure here

0
Can I get a screenshot of the GUI's structure please? JakyeRU 637 — 4y
0
There, I edited it. Nep_Ryker 131 — 4y

1 answer

Log in to vote
1
Answered by
JakyeRU 637 Moderation Voter
4 years ago

Okay, so we'll start by choosing a random player:

local Players = game.Players:GetPlayers();
local RandomPlayer = (Players[math.random(1, #Players)])

Players is an array (table). We are randomly picking a number between 1 and the length of the array. If there's only one player, the script has to pick a number between 1 and 1, which will be 1.

Changing the value of the NumberValue:

RandomPlayer:WaitForChild("PlayerGui").Role.ROLE.Value = 69

Any value (StringValue, Color3Value, RayValue, Vector3Value, NumberValue etc..) has a property called "Value". You can use that to change the value of the object. Another example would be:

local StringValue = Instance.new("StringValue")
StringValue.Name = "GameLeader"
StringValue.Value = "JakyeRU"

print(StringValue.Value)
0
Thanks! Nep_Ryker 131 — 4y
Ad

Answer this question