#How to do i make add a allowed team script to this

7 messages · Page 1 of 1 (latest)

brittle pine
#

So this script works perfectly fine, but i do not know how to add a another part to the script where only a certain team is allowed to run the command. if someone knows how to please help me out

light aurora
#

you'll want to refactor the check that compares message:lower to command and change it to this

if message:lower() == command and player.Team == insertTeamHere then
  -- run command
end

This checks the command, but then also checks that the player is on the team that's allowed to run ot

brittle pine
#

can u re-copypaste the script and put in the right area so that it works? i just started scripting today and im a little bit confused

#

-- Put this script in a ServerScriptService

local command = "re alive"
local teamToRespawn = game.Teams["Green"] -- Replace "YourTeamName" with the actual name of the team

local allowedTeamName = "AllowedTeam" -- Replace with the name of the allowed team
local function IsPlayerInAllowedTeam(player)
local team = player.Team
return team and team.Name == allowedTeamName
end

game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message:lower() == command then
RespawnTeamPlayers(teamToRespawn)
end
end)
end)

function RespawnTeamPlayers(team)
for _, player in pairs(team:GetPlayers()) do
RespawnPlayer(player)
end
end

function RespawnPlayer(player)
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0 -- Kill the player's character to respawn them
end
end
end

light aurora
#
-- Put this script in a ServerScriptService
local Teams = game:GetService("Teams")
local command = "re alive"

local teamToRespawn = Teams.Green
local allowedTeam = Teams.AllowedTeam -- change this to whatever team can run commands

game:GetService("Players").PlayerAdded:Connect(function(player)
    player.Chatted:Connect(function(message)
        if message:lower() == command and player.Team == allowedTeam then
            RespawnTeamPlayers(teamToRespawn)
        end
    end)
end)

function RespawnTeamPlayers(team)
    for _, player in pairs(team:GetPlayers()) do
        RespawnPlayer(player)
    end
end

function RespawnPlayer(player)
    local character = player.Character
    if character then
        local humanoid = character:FindFirstChild("Humanoid")
        if humanoid then
            humanoid.Health = 0  -- Kill the player's character to respawn them
        end
    end
end
brittle pine
#

thank you so much bro