So, I was scripting my own lava because I could’nt find the lava I wanted anywhere in the Toolbox, But when I take the player out of the lava, it continues it’s harming effect.
Anyone got a solution? Here is my entire script:
local lava = script.Parent
local burnplayer = lava.LavaSettings.LavaBurnsPlayer.Value
local lavadelay = lava.LavaSettings.LavaDamageDelay.Value
local lavadamage = lava.LavaSettings.LavaDamageValue.Value
local onDelay = lava.LavaSettings.OnDelay.Value
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
while onDelay == false do
otherPart.Parent.Humanoid:TakeDamage(lavadamage)
onDelay = true
wait(lavadelay)
onDelay = false
end
end
lava.Touched:Connect(onTouch)
local lava = script.Parent
local burnplayer = lava.LavaSettings.LavaBurnsPlayer.Value
local lavadelay = lava.LavaSettings.LavaDamageDelay.Value
local lavadamage = lava.LavaSettings.LavaDamageValue.Value
local onDelay = lava.LavaSettings.OnDelay.Value
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if onDelay = false then
otherPart.Parent.Humanoid:TakeDamage(lavadamage)
onDelay = true
wait(lavadelay)
onDelay = false
end
end
lava.Touched:Connect(onTouch)
local OnGoingLoop = false
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
local char = otherPart.Parent
if OnGoingLoop == false then
OnGoingLoop = true
while onDelay == false and humanoid do
local damage = false
local parts = GetTouchingParts(lava)
for i,part in pairs (parts) do
if damage == false then
if part.Parent == char then
damage = true
end
end
end
if damage then
otherPart.Parent.Humanoid:TakeDamage(lavadamage)
onDelay = true
wait(lavadelay)
onDelay = false
else
break
end
end
end
end
lava.Touched:Connect(onTouch)
I used a technique by @/buildthomas, it might not be the most efficent code but I believe it should work.
EDIT: Added a variable so it doesn’t start a loop everytime .Touched is fired.
Try not setting the variable of ondelay’s bool value and see how it goes.
local onDelay = lava.LavaSettings.OnDelay
local function onTouch(otherPart)
local humanoid = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if onDelay.Value == false do --no need a while loop here cus we only check for the bool and you made debounce cooldown!
otherPart.Parent.Humanoid:TakeDamage(lavadamage)
onDelay.Value = true
wait(lavadelay)
onDelay.Value = false
end
end