(lua newb)
function touch(damage) local rekt = damage.Parent:FindFirstChild("Humanoid").Health rekt = damage.Parent:FindFirstChild("Humanoid").Health -10 wait(1) end script.Parent.Touched:connect(touch)
why do I have to repeat the same line of code? I know that it won't work otherwise but why?
damage.Parent:FindFirstChild("Humanoid").Health = damage.Parent:FindFirstChild("Humanoid").Health -10
Hey NickLeBuilder,
local part = script.Parent; -- Set a variable for the part that will be touched; part.Touched:Connect(function(obj) -- Anonymous function with the Touched event. local hum = obj.Parent:FindFirstChild("Humanoid"); -- Declares a variable for the Humanoid(If there is one) if hum then -- Checks if it's a Character hum:TakeDamage(10); -- Takes away 10 health points. end -- end for if statement. end) -- end for the anonymous function.
~~ KingLoneCat
I see that your trying to make a kill block, and I recommend using this type of code rather than that, here is a code that works pretty efficiently:
script.Parent.Touched:Connect(function(hit) -- Fires when part is touched if hit.Parent:IsA("Model") then -- Checks if the hit.Parent is a character local hum = hit.Parent:FindFirstChild("Humanoid") -- Finds the humanoid hum.Health= hum.Health - 10 --Takes away the health end end)
Hope this helped :)