I've made a damage script for the kill parts in my obby,
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = 0 end end script.Parent.Touched:connect(onTouched)
but I want to eliminate most of these scripts to make sure that my obby runs as fast as possible.
Is there a way to make one script that detects when any of the kill parts (they are all grouped) are touched and then deal 100 damage to the humanoid that touched it?
I've tried putting all of the parts as children under the script and changed the script to say:
function onTouched(hit) local human = hit.Parent:findFirstChild("Humanoid") if (human ~= nil) then human.Health = 0 end end script.Child.Touched:connect(onTouched)
but that didn't seem to work.
local DamageParts = workspace.Parts:GetChildren() local function DealDamage(Touched) local Humanoid = Touched.Parent:FindFirstChildOfClass("Humanoid") if (Humanoid) then Humanoid:TakeDamage(Humanoid.Health*Humanoid.MaxHealth) end end for _,Part in pairs(DamageParts) do if (Part:IsA("BasePart")) then Part.Touched:Connect(DealDamage) end end