How to make lava disappear at the end of the game

Hey! I’m xt12t! Also known as K0rrupt!

I am currently making a flood escape type game, but I don’t know how to make the lava reset it’s position when the round ends. All feedbacks are appreciated!

Code:

Lava rise code:

local be = script.Parent
local lava = game.Workspace.Lava
local lavaSpeed = lava:GetAttribute("lavaSpeed")

local function onEvent()
	print("Start Lava")
	while true do
		lava.Size = lava.Size + Vector3.new(0, lavaSpeed, 0)
		lava.Position = lava.Position + Vector3.new(0, lavaSpeed/2, 0)
		wait(0.1)
	end
end

be.Event:Connect(onEvent)

image

Game timer code:

for i = lavaRise, 0, -1 do
			InRound.Value = true
			wait(1)
			
			Status.Value = "Lava Rises in ".. i .. " seconds!"
		end 
		be:Fire()
		
		for i = roundLength, 0, -1 do 
			InRound.Value = true
			wait(1)

			Status.Value = "Game: ".. i .. " seconds left!"
			wait(1)
		end
	end
end

image

Have the server fire a RoundEnded event or something that will turn off the lava rise loop, then reset its position.

local lavaSpeed = Vector3.new(0, 1, 0)
local lavaSpeedHalf = lavaSpeed / 2
local roundPlaying = true

RoundEnded:Connect(function()
    roundPlaying = false
end)

local function onEvent()
	print("Start Lava")
	local oldPos = lava.Position
	
	while roundPlaying do
		lava.Size += lavaSpeed
		lava.Position += lavaSpeedHalf
		task.wait(0.1)
	end
	task.wait(2) -- Buffer time

	lava.Position = oldPos
end

Where do I put that script? Lava Rise script ?

It’s just a localscript. You still have to edit your server scripts to fire all players that the lava stopped rising.

What do you mean? I don’t understand.

Nevermind, just merge what I wrote with your lava rise script. You don’t need the RemoteEvent since it’s all on the server.

For your Game timer code, put `roundPlaying = false’ after the countdown is done.

If they’re separate scripts, then merge them or use ModuleScripts so you can share variables between the scripts.

1 Like