I’m making a script to when a player touch the block, the player is killed, but isn’t working.
script.Parent.Touched:connect(function(touch)
local char = touch.Parent
if not char.Name == script.Parent.Parent.Name then
char.Humanoid.Health = 0
end
end)
Also I recommend you put some checks to make sure what is touching is a Character and not anything else, so your code is better off looking like this to make it a bit more safer
local part = script.Parent
part.Touched:Connect(function(touch)
local char = touch.Parent
local hum = char:FindFirstChild("Humanoid")
if not hum or char.Name == part.Parent.Name then return end
hum.Health = 0
end)
Is the dummy moving on the part? There needs to be some movement involved for Touched to activate, add a print statement in the event to see if it’s being ran.
I’d recommend adding an extra check to make sure the part you’re touching isn’t a hat.
function GetPlayerFromObj(obj)
if obj.Parent:FindFirstChild("Humanoid") ~= nil then
return obj.Parent
end
if obj.Parent.Parent:FindFirstChild("Humanoid") ~= nil then
return obj.Parent.Parent
end
return nil
end