I am trying to make the floor of my game destroy anything that’s a part and deal damage to anything that is a humanoid. How would I do that?
4 Likes
-- Insert this script into the part you want to be the floor
local part = script.Parent
Damage = 20 -- However much damage you want the floor to take
part.Touched:Connect(function(tpart) --tpart is the part that touched the floor
local foundHumanoid = tpart.Parent:FindFirstChild("Humanoid")
if foundHumanoid then
foundHumanoid:TakeDamage(Damage)
else
tpart:Destroy()
end
end)
Tell me if this doesn’t work for you
Also make sure to put this in a regular script, not a local one
4 Likes
In a script, inside of your floor part:
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
humanoid:TakeDamage(20) -- change this to the damage you want to be dealt
else
hit:Destroy()
end
end
4 Likes
It worked. Thanks for the help
1 Like