You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Ok. So. I’m trying to add a team filter to this detection zone. It’ll be use as a special ability that a player can use.
What is the issue? Problem : The damage zone damages the player that is using his ability, AND his teammates, which isn’t the expected result. I’m trying to make like, when the player uses his ability, it’ll damage the ennemies teams only.
What solutions have you tried so far? I tried to look for a solution in devforum, didn’t find one. I also tried to add a team statement to my script like :
if plr.Team ~= Team[“SCP-407”] then return end
but doing this will only detect one player. Also tried :
if plr.Team == Team[“SCP-407”] then continue end
if plr.Team ~= Team[“SCP-407”] then return end
and
if plr.Team == Team[“SCP-407”] then continue end
but nothing worked. Could you help me please? Script below :
local allies = {
"SH",
"Pizza",
"Obamium",
"BigShaq",
"IKEA",
"SCP-035",
"SCP-049",
"SCP-076",
"SCP-106",
"SCP-407",
"SCP-457",
"SCP-745"
}
local Team = game:GetService("Teams")
local players = game:GetService("Players")
local Hits = {}
game.ReplicatedStorage.MusicSCP.OnServerEvent:Connect(function()
script.Parent.Head.Music:Resume()
local part = script.Parent.FireDamageZone
local min = Vector3.new(part.Position.X-part.Size.X/2, part.Position.Y-part.Size.Y/2, part.Position.Z-part.Size.Z/2)
local max= Vector3.new(part.Position.X+part.Size.X/2, part.Position.Y+part.Size.Y/2, part.Position.Z+part.Size.Z/2)
local Region = Region3.new(min, max)
while wait(1) do
for _, Hit in pairs(game.Workspace:FindPartsInRegion3(Region, nil,math.huge)) do
local plr = players:FindFirstChild(Hit.Parent.Name)
if Hit.Parent:FindFirstChild("Humanoid") then
if Hits[Hit.Parent.Name] then continue end
if plr.Team == Team["SCP-407"] then continue end
Hits[Hit.Parent.Name] = true
Hit.Parent.Humanoid:TakeDamage(20)
delay(1, function()
Hits[Hit.Parent.Name] = nil
end)
end
end
end
end)
game.ReplicatedStorage.MusicSCPStop.OnServerEvent:Connect(function()
script.Parent.Head.Music:Stop()
end)
while wait(1) do
for _, Hit in pairs(game.Workspace:FindPartsInRegion3(Region, nil,math.huge)) do
local plr = players:FindFirstChild(Hit.Parent.Name)
local hum = Hit.Parent:FindFirstChildOfClass("Humanoid")
if not plr or not hum then continue end
if Hits[Hit.Parent.Name] or table.find(allies,plr.Team.Name) then continue end
Hits[Hit.Parent.Name] = true
hum:TakeDamage(20)
end
Hits = {}
end
while wait(1) do
for _, Hit in pairs(game.Workspace:FindPartsInRegion3(Region, nil,math.huge)) do
print("Getting part")
local plr = players:FindFirstChild(Hit.Parent.Name)
print("Getting player")
local hum = Hit.Parent:FindFirstChildOfClass("Humanoid")
print("Checking if part is a player")
if not plr or not hum then continue end
print("If not, skip")
if Hits[Hit.Parent.Name] or table.find(allies,plr.Team.Name) then continue end
print("If yes, continue")
Hits[Hit.Parent.Name] = true
hum:TakeDamage(20)
print("Damage player")
end
Hits = {}
print("DReset table")
end
I know the code does work, but something is going on durign the interactions that’s causing an issue. Maybe try this?
while wait(1) do
for _, Hit in pairs(game.Workspace:FindPartsInRegion3(Region, nil,math.huge)) do
local plr = players:FindFirstChild(Hit.Parent.Name)
local hum = Hit.Parent:FindFirstChildOfClass("Humanoid")
if not plr or not hum then continue end
if Hits[plr.Name] or table.find(allies,plr.Team.Name) then continue end
Hits[plr.Name] = true
hum:TakeDamage(20)
end
Hits = {}
end
Store the name of the player instea dof the name of the character?