Part detecting another part and player

Hi guys, Ive been trying to make it so that when the part touches the “death part” and the player is standing on it, it will kill the player and change their team. Im having trouble with it detecting that the death part is being touched while the player is also touched. Ive been trying for days and it dont work :frowning:

local part = script.Parent


local parts = game.Workspace:GetPartsInPart(part)

while wait(1) do
for _ , part in game.Workspace:GetPartsInPart(part) do
		print(part.Name)
		print(part.Parent.Name)
		
		if part.Parent:FindFirstChild("Humanoid")   and part.Name == ("death") then	
			print("ok he stepping on it")
			part.Parent:FindFirstChild("Humanoid").Health = 0
			for _, player in(game.Players:GetPlayers()) do
				player.Team = game.Teams.white
			end
		
		end
		
	end
end


Please help!

4 Likes

Try this but change the death part:

local part = script.Parent
local death = workspace.death -- Change this to the location of your death part

game:GetService("RunService").Stepped:Connect(function()
	local allTouchingParts = part:GetTouchingParts()
	
	for _, item in allTouchingParts do
		if not item.Parent:FindFirstChild("Humanoid") then continue     end
		if not table.find(allTouchingParts, death) then continue end
		local humanoid = item.Parent:FindFirstChild("Humanoid")
		humanoid:TakeDamage(humanoid.Health)
        for _, player in(game.Players:GetPlayers()) do
            player.Team = game.Teams.white
end
	end
end)

If for any reason you can’t reference the death part like I did then let me know.

1 Like

image

local Players = game:GetService("Players")

for _, v in pairs(script.Parent:GetChildren()) do
	if v:IsA("Part") then
		v.Touched:Connect(function(Hit)
			local Character = Hit.Parent
			local Humanoid = Character:FindFirstChildOfClass("Humanoid")
			
			if Humanoid then
				Humanoid.Health = 0
				
				Players:GetPlayerFromCharacter(Character).Team = game.Teams.White
			end
		end)
	end
end
1 Like

This kinda just has the main part kill the character without having touched death

this kinda worked, it only kills me once tho, any way to repeat it everytime u touch it after it has touched death?

local death = pathtodeathpart

script.Parent.Touched:Connect(hit)
   if hit and hit.Parent:FindFirstChild("Humanoid") then
      local player = game.Players:GetPlayerFromCharacter(hit.Parent)
      if player then
         local touching = workspace:GetPartsInPart(script.Parent)
         if touching[death] then
            player.Team = game.Teams.white
            hit.Parent.Humanoid.Health = 0
         end
      end
   end
end)

the part just kills the player without it touching death : ( Im trying to get it so that when the part touches death, and the player, the player dies

1 Like

edited to detect death part
hopefully it works now

1 Like

I dont know if you tried it yourself, but i tried it and even modified it, but somehow still doesnt work.
i fixed the function and added some stuff, but it looks like it still wont detect death for some reason im stuck on this ;-;

here is what i changed it to, i did try urs at first and it didnt work so i tried changing it and still:

local death = game.Workspace.death

script.Parent.Touched:Connect(function(hit)
if hit and hit.Parent:FindFirstChild("Humanoid") then
	local player = game.Players:GetPlayerFromCharacter(hit.Parent)
	if player then print("hey")
		local touching = workspace:GetPartsInPart(game.Workspace.ground)
			if touching == death then print("its working")
				player.Team = game.Teams.white
				hit.Parent.Humanoid.Health = 0
					end
				end
			
		end
	end)

touching is a table
try changing this line:

if touching == death then

to

if table.find(touching, death) then
2 Likes

tysm it finally worked ur a lifesaver : D

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.