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
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)