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
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)
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)
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
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.
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)