How do I make my script so only a player on a certain team can open the gui?

How can I make this script so it only opens when a player is in a certain team?

I have a toggleUI remote event in replicatedstorage

This script is in the frame.


local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ToggleUI")
local UI  = script.Parent.Parent -- The frame object of THIS ui
local Debounce = true -- prevents spamming

local CloseButton = script.Parent:WaitForChild("CloseB")

CloseButton.MouseButton1Down:Connect(function()
    UI.Enabled = false -- Force it to be false
end)

RemoteEvent.OnClientEvent:Connect(function() 
    if Debounce then
        Debounce = false
        UI.Enabled = not UI.Enabled -- Sets to the opposite boolean (true/false)
        wait(1)
        Debounce = true
    end
end)

This is another script in the brick itself.

local ClickDetector = script.Parent:WaitForChild("ClickDetector")
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ToggleUI")

-- When a player clicks the brick, we want the UI to toggle.
ClickDetector.MouseClick:Connect(function(player)
    RemoteEvent:FireClient(player) -- Only 'target' this player.
end)

Picture of Explorer: https://cdn.discordapp.com/attachments/557145682587418644/620936267173199872/Screen_Shot_2562-09-10_at_17.56.03.png

1 Like

Use this: https://developer.roblox.com/en-us/api-reference/property/Player/TeamColor

Or… you can make a custom team table for all of the players in the server, I feel that’s a little too extra though.

2 Likes

Thanks I found a way.

local ClickDetector = script.Parent:WaitForChild("ClickDetector")
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("ToggleUI")


script.Parent.ClickDetector.MouseClick:Connect(function(Player)
    if Player.Team.Name == "Team1" then 
        ClickDetector.MouseClick:Connect(function(player)
	RemoteEvent:FireClient(player) 
end)
    end 
end)
1 Like