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

Why can't I access PlayerGui in players?

Asked by 8 years ago

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
1
You never actually call the function. BinaryResolved 215 — 8y
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 CoolJohnnyboy 121 — 8y

1 answer

Log in to vote
1
Answered by
4Bros 550 Moderation Voter
8 years ago

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

0
FilteringEnabled is not set to true CoolJohnnyboy 121 — 8y
0
Does the output give you any errors? 4Bros 550 — 8y
0
No CoolJohnnyboy 121 — 8y
0
Output does not provide me with anything on errors CoolJohnnyboy 121 — 8y
Ad

Answer this question