Help with hiding GUI based on what team player is in

So, i was trying to make it so, that there’s 2 sets of GUI’s, 1 for each team and the script’s job is to prevent players from seeing/interacting with GUI meant for other team.
This is what i made(It’s LocalScript if you were wondering):

local Teams = game:GetService("Teams")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function()
	local plr = players.LocalPlayer
	if plr.Team == Teams.Team1 then
		script.Parent.Team2:Destroy()
	elseif plr.Team == Teams.Team2 then
		script.Parent.Team1:Destroy()
	end
end)

It simply won’t work, i went wrong somewhere and no idea where, so i post this here as my last resort, since i’m out of ideas myself.

Is this a local script or server script? If it’s a local script you can’t use PlayerAdded if it’s a server script it deletes all for all screens.

It literally says that it’s a LocalScript right above the block of code.
Edit: thank you for stating that, applying this knowledge, i came up with a solution of myself.

This should work, try it out!

local Teams = game:GetService("Teams")
local players = game:GetService("Players")

players.PlayerAdded:Connect(function()
	local plr = players.LocalPlayer
	if plr.Team.Name == "Team1" then
		script.Parent.Team2:Destroy()
	elseif plr.Team.Name == "Team2" then
		script.Parent.Team1:Destroy()
	end
end)

Oh sorry I didn’t see that my bad.

I already got a working solution of my own in place, but thanks still.
Edit: Also, i tested your script, just because why not, and it doesen’t even work.

Yeah, I just realized that. No problem, thought! :slight_smile: