How do i access playerGui in my script?

Hey, I’m trying to make a gui’s visible to true whenever the event is called, however I had some trouble passing on the player paramater from server so the remote events in the module script and the local script can access it, however I am getting this error.

I am calling my module in server, therefore i need player in server, then I’m using the module to fire a remote event to the client, then i need that player paramater in the local.

Here is my code.

--- SERVER ---
local gameStatusModule = require(game.ReplicatedStorage.GameStatusModule)
local roleModule = require(game.ReplicatedStorage.RoleModule)

local Players = game:GetService("Players")
local player = Players.PlayerAdded:Wait()

local inRound = false

local enoughPlayers = false

local isEnoughPlayers = gameStatusModule.notEnoughPlayers

while task.wait() do 
	if #Players:GetPlayers() < 2 then
		warn("not enough players")
		gameStatusModule.notEnoughPlayers("Need at least 1 more player to start!")
	elseif #Players:GetPlayers() >= 2 and inRound == false then
		warn("run intermission")
		gameStatusModule.intermission("Intermission: ")
		roleModule.roleSelector(player) -- how do I get player here?
		local isIntermissionFinished = gameStatusModule.intermission
		if isIntermissionFinished then
			inRound = true
			warn("run game")
			gameStatusModule.startGame("Drawer has ")
			local isGameFinished = gameStatusModule.startGame
			if isGameFinished then
				inRound = false
				warn("game ended")
			end
		end
	end
end
--- MODULE ---
local roleModule = {}

local Players = game:GetService("Players")
local Teams = game:GetService("Teams")

local roleEvent = game.ReplicatedStorage.RemoteEvents.RoleEvent

roleModule.roleSelector = function(player)
	local playerGui = player:WaitForChild("PlayerGui")
	local RoundGui = playerGui:WaitForChild("RoundGui")
	
	local RoleFrame = RoundGui.RoleFrame
	warn("display roles")
	roleEvent:FireClient(player)
end

return roleModule
--- ON CLIENT ---
local roleEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("RoleEvent")

local player = game.Players.LocalPlayer

roleEvent.OnClientEvent:Connect(function(player)
	local roundGui = player:WaitForChild("PlayerGui"):WaitForChild("RoundGui")
	
	roundGui.RoleFrame.Visible = true
end)

When you’re using the server you can’t access a client completely, you can fill your access by asking the client.

im sorry, can you give an example of how to do that

Use remoteevents, idk what else to say

i did, put how do i access the player on the server, to then use the paramater on my other scripts

Never share replicated information between the server and clients, clients can get the amount of players by themselves, by using the server you’re slowing the game’s performance.

When you call FireClient, the OnClientEvent will only run for the player that the FireClient function was fired to. The reason why you are receiving this error is because you haven’t passed any other arguments from FireClient, as the first argument for FireClient (which is the player instance) will not be passed as the first parameter to the OnClientEvent.

To fix this, just add a second argument to the FireClient function, which would be the same player instance (or you can also use the player’s name). However, this is not actually necessary as you can just use the LocalPlayer in the local script, since as I mentioned before, the OnClientEvent will only run to the player who FireClient was fired for.

--- ON CLIENT ---
local roleEvent = game.ReplicatedStorage.RemoteEvents:WaitForChild("RoleEvent")

local player = game.Players.LocalPlayer

roleEvent.OnClientEvent:Connect(function() -- removed the player parameter as it is 'nil'
	local roundGui = player:WaitForChild("PlayerGui"):WaitForChild("RoundGui")
	
	roundGui.RoleFrame.Visible = true
end)

You can get playerGui in your script by putting “script.Parent.Parent.PlayerGui” or whatever the path is.