How can I fix this damage zone?

You can write your topic however you want, but you need to answer these questions:

  1. 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.

  2. 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.

  3. 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)
3 Likes

Try changing your while loop to 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[Hit.Parent.Name] or table.find(allies,plr.Team.Name) then continue end
		Hits[Hit.Parent.Name] = true
		hum:TakeDamage(20)
	end
	Hits = {}
end

It doesn’t seems to work, I think it returns the function when the player is in the team

That isn’t possible as there’s only continue, no return. Did anything change when you were trying out the script I proposed?

In the original script, every entities (rig) presents in the zone took damage. Now, any rig seems to be affected

Hmm, try adding print statements to see what may be wrong?

Added print everywhere :

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

Every prints runs

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?

Doesn’t work either… THis issue is very weird, don’t understand why it acts like this

I think you may need to debug by checking everything that is in that loop, plr, hum, Hits[plr.Name], the table.find, something is going on

I added a print(Hits) but it shows nothing in the output

What about Hits[plr.Name] right before the continue statements?

You already did it at this line no? :
if Hits[plr.Name] or table.find(allies,plr.Team.Name) then continue end

No I mean to print that, I should’ve been more specific, sorry!

Ok, it print me this :
image

Wher edid you put that? Put it after the local plr line

I put it here :

Okay put it after the if not plr or not hum then continue end line

image

There is something wrong with your Hits table let me see if I can see something