#How to do i make add a allowed team script to this
7 messages · Page 1 of 1 (latest)
You'll want to check the Player's team, you can do this by using
if Player.Team == someTeam then
-- run command
end
You can reference the team by getting it out of the Teams service similar to
local Teams = game:GetService("Teams")
local YourTeam = Team.Green
though it looks like you're already fetching it
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
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
-- 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
thank you so much bro