local Player = script.Parent.Parent.Parent if script.Parent.Parent.Name == "PlayerGui" then if Player.Team.TeamColor == BrickColor.new("Dark stone grey") then -- Checks if the team is a prisoner print("Prisoner") script.Parent:Destroy() -- removes it if your team is a prisoner end if Player.Team.TeamColor == BrickColor.new("White") then -- checks if your team is a civilian print("Civilian") end end
How it works: it sees if you're a prisoner then deletes the GUI so you cant change and get unjailed and prints "Prisoner"
If you're a civilian then it just prints "civilian"...
It did work, though it only checked once. The if will not execute on its own each time.
Using the GetPropertyChangedSignal
function we can listen for a specific property change.
local Player = game:GetService("Players").LocalPlayer Player:GetPropertyChangedSignal("Team"):Connect(function() if Player.Team.TeamColor == BrickColor.new("Dark stone grey") then print("Prisoner") script.Parent:Destroy() elseif Player.Team.TeamColor == BrickColor.new("White") then print("Civilian") end end)
Basically the code executes each time the team changes and only when the team changes.
If you do not know about events already check them out here: events