Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i use GetPlayer function to change everyones PlayerGui?

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)

3 comments

0

I tried my best to make the question understandable.

0

It is best to do thison the client side just notify all players that they should start the countdown

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

2 answers

✓ Accepted answer

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

1 comment

0

omg thank you so much

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

4 comments

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?

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

0

I tried to change PlayerGuis from a server script and it worked on FE. Not sure if it's just me or not.

0

Wrong^ Server cannot modify client objects. Tools are an exception. ANYTHING GUI related cannot be modified from the server/shouldn’t be.

This discussion is preserved as it was. New answers, comments, and votes are closed.