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

Why can't I access PlayerGui in players?

My script is supposed to make things inside a GUI active so that players can see if they won/lost the game.

The giving of XP works, but for some reason, the game won't access PlayerGui (Is it even possible to access in the first place?)

Everything is named correctly

Can someone please help me? Here's the script:

function EndGame()
	local player = game.Players:getPlayers() 
	for i = 1, #player do
		if player[i].TeamColor == BrickColor.new("Bright green") then
			player[i].PlayerGui.EndGameGUI.Frame.Victory.Visible = true
			player[i].Other.XP.Value = player[i].Other.XP.Value + 300
		elseif player[i].TeamColor == BrickColor.new("Bright red") then
			player[i].PlayerGui.EndGameGUI.Frame.Defeat.Visible = true
			player[i].Other.XP.Value = player[i].Other.XP.Value + 150
		end
	end
end

2 comments

1

You never actually call the function.

0

The function occurs. I'm just posting a small section of the script. The function gives XP but does not do anything to the GUI in question

1 answer

If you have the FilteringEnabled property in the workspace set to true, then the server will not be able to access the player's PlayerGui. When this property is set to true, the playergui will not replicate to the server and only the client will have access to it. If you want to access it then you should either turn off FilteringEnabled (wouldn't recommend) or use remote events to communicate with the client and change their playerguis.

Example: Create a remote event in replicatedstorage

--Server Script
local event = game:GetService'ReplicatedStorage':WaitForChild'RemoteEvent'
function EndGame()
event:FireAllClients("end")
end


--Local Script
local event = game:GetService'ReplicatedStorage':WaitForChild'RemoteEvent'
repeat wait() until game.Players.LocalPlayer
local player = game.Players.LocalPlayer


event.OnClientEvent:connect(function(arg)
	if arg == "end" then
		 if player.TeamColor == BrickColor.new("Bright green") then
		          player.PlayerGui.EndGameGUI.Frame.Victory.Visible = true
		          player.Other.XP.Value = player.Other.XP.Value + 300
		      elseif player.TeamColor == BrickColor.new("Bright red") then
		        player.PlayerGui.EndGameGUI.Frame.Defeat.Visible = true
		        player.Other.XP.Value = player.Other.XP.Value + 150
		end
	end
end

4 comments

0

FilteringEnabled is not set to true

0

Does the output give you any errors?

0

No

0

Output does not provide me with anything on errors

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