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

Make a value change in a GUI in PlayerGui for every player in the server from touching a part ?

Asked by 5 years ago
Edited 5 years ago

I have a part with a script inside it. https://gyazo.com/935fe7946b0ee61853e020556b7cfd0b

The script says so:

local deb = true
local children = game.Players:GetChildren()

script.Parent.Touched:Connect(function(hit)
    if deb == true then
        deb = false
        wait(0.005)
        game.Players:GetChildren().PlayerGui.TextGui.TextLabel.Line.Value = 12
        script.Parent:Destroy()
    end
end)

Now, every player has a GUI in the PlayerGui Sub-Class named 'TextGui', it contains a Int Value inside a TextLabel. I tried :GetDescendants, but was confusing. What do I need to change/do in the script? Thanks!

1 answer

Log in to vote
0
Answered by
megukoo 877 Moderation Voter
5 years ago

You'll have to learn how to use for loops to achieve what you want. for loops can either be generic or numeric, and in your case we'll use a generic one.

Here's a small example of a generic for loop:

local Players = game:GetService("Players")

for index, value in pairs(Players:GetPlayers()) do
    print(index, value)
end

You'll notice it prints something like

1 WaterIsIceSoup and that's cool and all. What this is doing is going through the table of :GetPlayers(), which looks like this if I'm alone in a server:

{game.Players.WaterIsIceSoup} - note that it is a direct reference to my Player object.

Using our newfound knowledge, we can create a script to affect all Players ingame.

local Players = game:GetService("Players")

for index, player in pairs(Players:GetPlayers()) do
    player:LoadCharacter()
end

This script respawns everyone in the game. n i f t y.

If you wanted to change a value in every player, that'd look something like this:

local Players = game:GetService("Players")

for index, player in pairs(Players:GetPlayers()) do
    player.Wins.Value = 9999
    -- free wins
end

The problem is that your value is inside the TextLabel. Server scripts by default cannot see any GUI in a PlayerGui, and should not attempt to handle them.

What I suggest is putting the IntValue inside the Player itself when they join, then use the above example to modify every player's stats. You'll need to use PlayerAdded to put the IntValue in Players when they join.

Wiki articles on PlayerAdded. https://developer.roblox.com/en-us/api-reference/event/Players/PlayerAdded

Hopefully this sets you on the right track.

0
I tried the for loop but totally forgot the :GetPlayers() function, thanks so much! shephali 3 — 5y
Ad

Answer this question