The kill Part Dont work with New Accessories like Jackets or Pants

robloxapp-20230302-1533324.wmv (825.7 KB)
robloxapp-20230302-1535047.wmv (1021.0 KB)

local Parts = workspace.Map.didParts:GetChildren()
local D = false
local Damge = 15

for _,Parts in Parts do
	if Parts:IsA("Part") then
		
		Parts.Touched:Connect(function(plr)
			local LocalPlayer = game.Players:GetPlayerFromCharacter(plr.Parent)
			local Humanoid = plr.Parent:FindFirstChild("Humanoid")
			if  D == false then
		        D = true
				Humanoid.Health = Humanoid.Health - Damge
				wait(1)
				D = false
			end
			if Humanoid.Health == 0  then
				LocalPlayer.Robry.Value = 0
			end
		end)
	end
end


this is the script
image
error cod
how i can fix this

Title is misleading. Please check the error before naming your title. You’re shadowing Parts.

local Players = game:GetService("Players")
local Parts = workspace.Map.didParts
local debounce = false
local dmg = 15

for _, part in Parts:GetChildren() do
	if not part:IsA("BasePart") then continue end
	part.Touched:Connect(function(touchedPart)
		if debounce then return end
		local Player = Players:GetPlayerFromCharacter(touchedPart.Parent)
		if not Player then return end
		local Humanoid = touchedPart.Parent:FindFirstChild("Humanoid")

		debounce = true
		Humanoid.Health -= dmg
		if Humanoid.Health <= 0 then
			Player.Robry.Value = 0
			debounce = false
			return
		end
		task.delay(1, function()
			debounce = false
		end)
	end)
end
1 Like

This should make your script more efficient:

local debounce = {} -- Different debounce for each player
local damage = 15

for _, part in workspace.Map.didParts:GetChildren() do
	if part:IsA("BasePart") then
		part.Touched:Connect(function(hit)
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			local hum = player.Character.Humanoid
			if debounce[player] then return end
            debounce[player] = true
            hum:TakeDamage(damage)
            task.wait(1)
            debounce[player] = nil -- Don't set this to false, set it to nil
			if hum.Health == 0  then
				player.Robry.Value = 0
			end
		end)
	end
end
1 Like

idont know how u fix this but thanks

completely forgot about that LOL

1 Like

Personnaly i would do it like this

local PlayerService = game:GetService("Players")

local Map = workspace:WaitForChild("Map",300)
local KillParts = Map and Map:WaitForChild("didParts",30)

local State = true
local Damage = 15
local Cooldown = 1
------------------------------------------------------------------------
local function Touched(Part)
	Part.Touched:Connect(function(Hit)
		local Player = PlayerService:FindFirstChild(Hit.Parent.Name)
		local Robry = Player and Player:FindFirstChild("Robry")
		local Humanoid = Hit.Parent:FindFirstChild("Humanoid")
		
		if Player and Humanoid and Robry and State then			
			State = false
			Humanoid:TakeDamage(Damage)
			
			if Humanoid.Health <= 0 then
				Robry.Value = 0
			end
			
			task.wait(Cooldown)
			State = true
		end
	end)
end
------------------------------------------------------------------------
for _, Part in pairs(KillParts:GetChildren())do
	if Part:IsA("Part") then
		Touched(Part)
	end
end
1 Like

Just to clarify, did you want accessories to trigger kill parts, or just the user’s limbs? Either way, the best way would be to hit the player a defined hitbox welded to their root part, and detect that instead.

1 Like

Absolutely not :sweat_smile:
You can use this to detect accessories as well as body parts ^^

script.Parent.Touched:Connect(function(Hit)
	local Character = Hit:FindFirstAncestorWhichIsA("Model")
	print(Hit.Name, Hit.Parent.Name, Character.Name)
end)
1 Like