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