PlayerGui visible isn't working

This script make gui visible when players switches to prisoner team. Issue I am having is the Gui won’t become visible. I used prints() to narrow in on the issue and it leads to the Player.PlayerGui.MainUI.Enabled = true part.

local Players = game:GetService("Players")

local Teams = game:GetService("Teams")



Players.PlayerAdded:Connect(function(Player)

	Player.CharacterAdded:Connect(function(Character)

		if Player.Team == Teams.Prisoner then

			Player.PlayerGui.MainUI.Enabled = true

			Player.PlayerGui.MoneyGui.Enabled = true
1 Like

the problem:

instead do:

local Players = game:GetService("Players").LocalPlayer

‘Players’ is getting a whole Folder. .LocalPlayer is the single player.

2 Likes

Also, I suggest removing spaces from your script, it’s a bad habbit and make’s your script’s messy, there’s other problems. Here’s the fixed script:

local plr = game:GetService("Players").LocalPlayer
local Teams = game:GetService("Teams")

Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if Player.Team == Teams.Prisoner then
			Player.PlayerGui.MainUI.Enabled = true
			Player.PlayerGui.MoneyGui.Enabled = true 
       end
    end
end)
1 Like

Also, if I was right please give me the solution.

It still doesn’t work I am rn trying to fine the issue using prints

Can you show the rest of the script please, maybe it’s that.

That’s the whole script and its in serverscriptservice

That’s why. Make the script a localscript and put it in ScreenGui

Let me know if it works.

1 Like

Does it work? If it does not I know how to fix it, as I tested the script myself

Ok it gives me an error:
PlayerAdded is not a valid member of Player “Players.theking66hayday”

If trying to show UI, you need to do that through a clientscript. Try something like this in StarterCharacter scripts:

local player = game.Players.LocalPlayer
local gui = player:WaitForChild('PlayerGui')

function onTeamChange(newTeam)
	if newTeam.Name == "Whatever" then
		gui:WaitForChild("MoneyGui").Visibile = true
	end
end

player:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(player.Team)
end)

1 Like

Alright instead do

local Joints = game:GetService("JointsService") -- A variable for when something has entered.
local Player = game:GetService("Players").LocalPlayer -- The actual player

TeamTargeted = "Prisoner" -- Exact capitals, Letters

function CheckTeam() -- A function to check
    while wait(0.5) do -- a loop
       if Player.Team == TeamTargeted then -- if the team is TeamTargeted
       script.Parent.MoneyGui.Enabled = true -- Enable
       script.Parent.MainUI.Enabled = true -- Enable
   end
end)

task.wait(Joints) -- Wait when the player joins
CheckTeam() -- Fire the function made

I hope that works.

MAKE SURE ITs A LOCAL SCRIPT AND IN SCREENGUI

Does it work? Please let me know, if it does give me the solution.

Inefficient. A LocalScript in StarterCharacterScripts is more than enough for the job. And you don’t need a while loop, which in fact keeps running forever, to check if someone’s in a team. Even worse, you use wait().

@UltraDad123 gave the solution already, which is effective and works when the team is changed. Also, don’t chase solutions, it’s not like they’re special badges.

1 Like

No he did not.

"Visible"
Instead, use Enabled.

Also, are you in 2020? You use task.wait()

You’re the one using while wait(0.5) do. If you’re that picky then help yourself:

local LocalPlayer = game.Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild('PlayerGui')

local function onTeamChange(newTeam)
	if newTeam.Name == "Prisoner" then
		PlayerGui:WaitForChild("MoneyGui").Enabled = true
		PlayerGui:WaitForChild("MainUI").Enabled = true
	end
end

LocalPlayer:GetPropertyChangedSignal("Team"):Connect(function()
	onTeamChange(LocalPlayer.Team)
end)

Can’t bother myself to write a new one.

Sorry for stealing the code lol.

2 Likes

Must be, JointsService wasn’t deprecated then :wink:

Just stop fighting, it’s everyday. Employees are probably stressed out, no doubts.