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

How do i use GetPlayer function to change everyones PlayerGui?

Asked by
CjayPlyz 643 Moderation Voter
5 years ago

can anyone tell me how i can change everyones playergui using getplayer?

let's say i have a textlabel in a screengui inside the startgui. now how do i get all player and change the text in textlabel inside they're playergui?

Here's a script i just made while making this question so i don't really know if this will work. Will this script work or does it need some changes?

local function start ()

local players = game.Players:GetPlayers()

players.PlayerGui.TextLabel.Text = 30

for i=1, 30 do

    wait(1)

    players.PlayerGui.TextLabel.Text = players.PlayerGui.TextLabel.Text - 1

end

end)
0
I tried my best to make the question understandable. CjayPlyz 643 — 5y
0
It is best to do thison the client side just notify all players that they should start the countdown User#5423 17 — 5y
0
yes that was the original plan but bugs started to come out so im trying my best not to use client side as much as possible. or just rewrite the whole script CjayPlyz 643 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

This is because you are trying to find the PlayerGui in a table. You need a for loop to index the Player objects IN the table. Another error is on line 11. You would get an error for performing arithmetic on a string value.

Side note, server cannot access PlayerGui and shouldn’t anyways! And yes I am using a RemoteEvent to do this. You’re welcome.

-- LocalScript
local remote = Instance.new'RemoteEvent'
remote.Name = 'GuiRemote'
remote.Parent = game:GetService'ReplicatedStorage'

local textlabel = script.Parent -- i put it under the textlabel

remote.OnClientEvent:Connect(function()
    for i = 30, 0, -1 do
        if i == 0 then
            textlabel.Text = ""
            break
        end

        textlabel.Text = "Countdown: ".. i
        wait(1)
    end
end)

From server:

-- Server script 

local rep = game:GetService"ReplicatedStorage"

function start() -- There was a space between start and the brackets, remove it
    for _, v in pairs(game:GetService("Players"):GetPlayers()) do
        rep:WaitForChild("GuiRemote"):FireClient(v)
    end
end
0
omg thank you so much CjayPlyz 643 — 5y
Ad
Log in to vote
2
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
5 years ago

The problem is that you can't change playergui from the server.

Your best solution would be to use a remote event to send over that people should start the countdown. (Don't forget to also do the countdown on the server.)

0
I see. do you think the cause of having the countdown having non random negative numbers was because of not also doing the countdown on the server? CjayPlyz 643 — 5y
0
If you start a countdown of 30 on the server, you should send over to all the clients that a countdown of 30 has started. Then use tick() to check how much time has actually past, it's a rookie mistake to only use wait(1), because that can slow down to even 5x as much on slow devices/servers (Which is also why wait() returns the actual time waited.) RubenKan 3615 — 5y
0
I tried to change PlayerGuis from a server script and it worked on FE. Not sure if it's just me or not. SCP774 191 — 5y
0
Wrong^ Server cannot modify client objects. Tools are an exception. ANYTHING GUI related cannot be modified from the server/shouldn’t be. User#19524 175 — 5y

Answer this question