Damage players while touching a zone

Hello !
I’m trying to make like when the player press left button, it plays an unnatural music that damage player if they hear it. I’ve done this part, but the damage part is broken :
1/ It seems that it can only damage one player at time
2/ It does weird damage (see the video bellow) even if player doesn’t hold left click he still takes damage
The script :

local Team = game:GetService("Teams")
local players = game:GetService("Players")
local isTouched = false
local Debounce = false
local damage = {}



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 _, part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do
			local plr = players:GetPlayerFromCharacter(part.Parent)
			if not plr or table.find(damage, plr.Name) then continue end
			local hum = part.Parent:FindFirstChild("Humanoid")
			if not hum then continue end
			if hum and plr.Team ~= Team["SCP-407"] then
				table.insert(damage, plr.Name)
				hum:TakeDamage(20)
			end
		end
		damage = {}
	end
end)

https://cdn.discordapp.com/attachments/820625409229717525/829303250712526858/Black_Albis_Place_Number__14_-_Roblox_Studio_2021-04-07_12-34-48.mp4

3 Likes
  1. Try doing a local server instead of having a humanoid with no player, because, I think this is causing it to not work.
local plr = players:GetPlayerFromCharacter(part.Parent) --It's a dummy, there is no player.

Imma test with 2 players then…
But how can I fiw the weird damage thing

Try instead of using if someone touches it, try and create a trigger that damages ONLY when the HumanoidRootPart or Torso is within the area instead of just the whole character, so it only damages them for one part.

with

local HRP = part.Parent:FindFirstChild("HumanoidRootPart")
If HRP then

?

That could work, because at the moment, you’re damaging them EACH time they touch the zone, and with R15, there are a crap ton of parts of a player.

THis thime, it doesn’t detect the user :

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 isTouched = false
local Debounce = false
local damage = {}



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 _, part in pairs(game.Workspace:FindPartsInRegion3(Region,nil,math.huge)) do
			local plr = players:GetPlayerFromCharacter(part.Parent)
			if not plr or table.find(damage, plr.Name) then continue end
			local HRP = part.Parent:FindFirstChild("HumanoidRootPart")
			if HRP then 
				if plr.Team ~= Team["SCP-407"] then
					table.insert(damage, plr.Name)
					part.Parent:FindFirstChild("Humanoid"):TakeDamage(20)
				end
			end
		end
		damage = {}
	end
end)

game.ReplicatedStorage.MusicSCPStop.OnServerEvent:Connect(function()
	script.Parent.Head.Music:Stop()
	damage = {}
end)

Ok everybody, after trying a lot (and a lot of frustration and FPS drops)
I got this script :

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:GetPlayerFromCharacter(Hit.Parent)
			if Hit.Parent:FindFirstChild("Humanoid") then
					if Hits[Hit.Parent.Name] then
						return
					end
				Hits[Hit.Parent.Name] = true
				if plr.Team ~= Team["SCP-407"] then
					Hit.Parent.Humanoid:TakeDamage(20)
				end
					delay(1, function()
						Hits[Hit.Parent.Name] = nil
					end)
				end
		end
	end
end)

Problem is that it only detect one player

Rectification : It detect players, but the second player is damaged only when he enter/leaves the zone