Hi, I have made lava that works like jump pad and deals damage, but I have problem with it; It sometimes deals double or even triple damage. I made debounce table that makes lava unable to deal double or triple damage to you, but it still doing it.
Here’s my code
local damagePlayers = {}
local min = workspace.LavaWithCollision.Position - (.5 * workspace.LavaWithCollision.Size)
local max = workspace.LavaWithCollision.Position + (.5 * workspace.LavaWithCollision.Size)
local region = Region3.new(min, max)
local runService = game:GetService("RunService")
while wait() do
for index, part in pairs(workspace:FindPartsInRegion3(region, nil, 5000)) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
if part.Parent.Humanoid.Health ~= 0 then
if not table.find(damagePlayers, part.Parent) then
table.insert(damagePlayers, part.Parent)
part.Parent.Humanoid:TakeDamage(25)
wait()
part.Parent.Humanoid.JumpPower = 100
part.Parent.Humanoid.Jump = true
wait(0.1)
part.Parent.Humanoid.JumpPower = 50
wait(0.3)
table.remove(damagePlayers, table.find(damagePlayers, part.Parent))
end
end
end
end
end
Increase the wait(0.3), that should work. If not then make sure you insert the name of the player and check for that name before damaging the player. Also your hitbox might be to large.
local damagePlayers = {}
local min = workspace.LavaWithCollision.Position - (.5 * workspace.LavaWithCollision.Size)
local max = workspace.LavaWithCollision.Position + (.5 * workspace.LavaWithCollision.Size)
local region = Region3.new(min, max)
local runService = game:GetService("RunService")
print(region)
while wait() do
for index, part in pairs(workspace:FindPartsInRegion3(region, nil, 5000)) do
if part.Parent:FindFirstChild("Humanoid") ~= nil then
if part.Parent.Humanoid.Health ~= 0 then
if not table.find(damagePlayers, part.Parent.Name) then
table.insert(damagePlayers, part.Parent.Name)
print(damagePlayers[1])
part.Parent.Humanoid:TakeDamage(25)
wait(0.3)
table.remove(damagePlayers, table.find(damagePlayers, part.Parent.Name))
end
end
end
end
end