Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

[Help] How do I make this so it only opens for a certain team when clicked?

Asked by 5 years ago

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.

-- We want to wait for the RemoteEvent to tell us to toggle the UI.
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() -- Call the ToggleUI Function (no arguments)
    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 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

You can use Player.Team to see what Team they are on and just compare it to what the team they should be is.

One thing though is that I strongly discourage that as a "Can this player have this OP gun when they press this button?"

Instead use the RE to as well check if they should have the gun, so just add a:

local goodTeam = Instance.New("Team")
RE.OnServerClient:Connect(function(plr)
    local plrTeam = plr.Team
    if plrTeam == goodTeam then
        print("Now the player can actually have the weapon")
    end
end)
Ad

Answer this question