This script is disabled on purpose, but when the other script is activated, it creates a "part" scaled 60,60,60 radius and it is a kill zone purpose. when it enters the zone it does 2k damages, but checking the output, I see 20+ "damage" prints and what gives a whooping 40k damage and that's too much. How do I fix this script? Thanks.
And when it does go over 2k damage, the health bar glitches and there's this long red line above my screen through the roblox default health bar.
--Kill OnTouch function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) then -- if a humanoid exists, then print("damage") humanoid:TakeDamage(2000) end end script.Parent.Touched:connect(onTouch)
Thats because the character has multiple parts that can each touch the part mutliple times causing the function to constantly run. To solve this you can add a debounce so the code can only run once every few seconds.
Edited so there is a debounce for each individual character:
--Kill OnTouch function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if (humanoid ~= nil) and not part:FindFirstChild("Debounce") then -- if a humanoid exists, then print("damage") local DB = Instance.new("StringValue", part.Parent) DB.Name = "Debounce" humanoid:TakeDamage(2000) wait(3) -- waits 3 second before it can deal damage again DB:Destroy() end end script.Parent.Touched:connect(onTouch)
The reason this might be happening is that multiple parts of the body touch the kill zone to do this you need to add something called a debounce.
local Debounce = false function onTouch(part) local humanoid = part.Parent:FindFirstChild("Humanoid") if Debounce == false then Debounce = true if (humanoid ~= nil) then print("damage") humanoid:TakeDamage(2000) end wait(SETDELAYHERE) Debounce = false end) script.Parent.Touched:connect(onTouch)
its basically what everyone above said, there is no limit o how many times an object can me touched, its kind like while true do loop with no wait (ouch), so ur gonna need to use debounce, which is pretty easy