How do you access the PlayerGui?

Ok so I’m trying to access the PlayerGui from the server so all players can see. But it is not working…

 -- Serverscript in serverscriptservice
game.ReplicatedStorage.ShowImage.OnServerEvent:Connect(function()
   game.Players:GetPlayers().PlayerGui.MostKills.Frame.Visible = true
end)

-- local script, a child of a gui
 game.ReplicatedStorage.ShowImage:FireServer()

Ok so the playerGui part is wrong

4 Likes

You should be modifying UI on the client, not the server. Players:GetPlayers returns a table, I don’t know what you were trying to do.

-- Local script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local client = Players.LocalPlayer

ReplicatedStorage.ShowImage.OnClientEvent:Connect(function(visible)
    client.PlayerGui.MostKills.Frame.Visible = visible
end)

ReplicatedStorage.ShowImage:FireServer()

Then on a server script you would do:

local ReplicatedStorage = game:GetService("ReplicatedStorage")

ReplicatedStorage.ShowImage.OnServerEvent:Connect(function(player)
    ReplicatedStorage.ShowImage:FireAllClients(true)
end)

This is just an example

13 Likes

So this would show the gui to all players in the game? (Thanks for telling my error)

Yes it would. RemoteEvent:FireAllClients fires to all clients.

1 Like

You should give a Solution mark to @sjr04

1 Like

For some reason, the frame will not turn visible. I set the frame, visibility to false by the way, and no errors in script analysis or output. (sorry for the late response)

Could you show us some code? Specifically, code involved in that process?

My code is at the top of this topic

1 Like

These should be swapped. Don’t do a OnServerEvent, do OnClientEvent on the client. Instead of Firing the server, fire the client.

Ok thanks for letting me know!

1 Like

If that reply helped fix your issue, I would appreciate it being marked as the solution :slight_smile:
Generally, it’s best to mark solutions so people scrolling by know the issue is solved.

3 Likes

This helped me a lot, I didn’t even think about using it like that, and then if you want it for just that one person put :FireClient()