Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local TARGET_BLOCK_NAME = "Kill" -- Ganti ini kalau kamu mau pakai nama lain, contoh: "Lava", "DangerZone"
- local DAMAGE_PER_SECOND = 10
- local REGEN_PER_SECOND = 1
- local TOUCH_DELAY = 0.2
- local touchingPlayers = {}
- local function isStillTouching(part, character)
- for _, limb in ipairs(character:GetChildren()) do
- if limb:IsA("BasePart") then
- for _, touching in ipairs(limb:GetTouchingParts()) do
- if touching == part then
- return true
- end
- end
- end
- end
- return false
- end
- local function applyDamage(part, character)
- local humanoid = character:FindFirstChild("Humanoid")
- if not humanoid then return end
- local id = character:GetFullName()..part:GetFullName()
- if not touchingPlayers[id] then
- touchingPlayers[id] = true
- while touchingPlayers[id] and humanoid.Health > 0 do
- humanoid:TakeDamage(DAMAGE_PER_SECOND * TOUCH_DELAY)
- wait(TOUCH_DELAY)
- end
- end
- end
- local function startRegen(part, character)
- local humanoid = character:FindFirstChild("Humanoid")
- if not humanoid then return end
- local id = character:GetFullName()..part:GetFullName()
- wait(0.2)
- if isStillTouching(part, character) then return end
- while not touchingPlayers[id] and humanoid.Health < humanoid.MaxHealth do
- local target = math.min(humanoid.Health + REGEN_PER_SECOND * TOUCH_DELAY, humanoid.MaxHealth)
- local current = humanoid.Health
- local steps = 5
- local interval = TOUCH_DELAY / steps
- for i = 1, steps do
- if touchingPlayers[id] then return end
- humanoid.Health = current + (target - current) * (i / steps)
- wait(interval)
- end
- end
- end
- local function setupKillBlock(part)
- part.Touched:Connect(function(hit)
- local player = game.Players:GetPlayerFromCharacter(hit.Parent)
- if player then
- applyDamage(part, hit.Parent)
- end
- end)
- part.TouchEnded:Connect(function(hit)
- local player = game.Players:GetPlayerFromCharacter(hit.Parent)
- if player then
- local id = hit.Parent:GetFullName()..part:GetFullName()
- touchingPlayers[id] = nil
- coroutine.wrap(function()
- startRegen(part, hit.Parent)
- end)()
- end
- end)
- end
- -- Pasang ke semua balok bernama sesuai TARGET_BLOCK_NAME
- for _, obj in ipairs(workspace:GetDescendants()) do
- if obj:IsA("BasePart") and obj.Name == TARGET_BLOCK_NAME then
- setupKillBlock(obj)
- end
- end
- -- Kalau ada balok baru bernama TARGET_BLOCK_NAME
- workspace.DescendantAdded:Connect(function(obj)
- if obj:IsA("BasePart") and obj.Name == TARGET_BLOCK_NAME then
- setupKillBlock(obj)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement