Need help fixing The Floor Is Lava script (Mainly GUI appearing problems)

Hey, Scripters!

Important: Here is how the game is supposed to work:
When a player joins the game, they are put into a Player folder for people who aren’t currently participating in a round. When one player is in the lobby/folder, a 10-second Gui countdown is supposed to start. Once it hits zero, the Gui is supposed to announce that the round is starting and teleport the players to the map, moving them to an Ingame folder. After 5 seconds, a lava block is spawned under the map and is supposed to rise every 2 seconds. If a player touches the lava, 5 health will be taken from them every second. If a player dies, they are moved back to the Player folder and cannot play until the round is over. If the Ingame folder has zero players, the Gui will display that the round has ended, the lava block will disappear, and the countdown process will restart.

Problems
I just finished writing this “The Floor Is Lava” script and, unfortunately, when I went to test it, it didn’t work as planned. Here are my problems:

  • None of the GUI updates when it is supposed to
  • When the round ends, the lava block is not destroyed
  • The lava debounce doesn’t function properly
  • If a player stands still, they can avoid taking damage

Here is the code, I will be responding to anyone who can help and if you can help me with all of these, it would mean a lot. Thanks, scripters! P.S. is a server script in ServerScriptService

--The Floor Is Lava!

local PlayerFolder = game.Workspace.PlayerFolder --Folder where lobby players are kept
local InGameFolder = game.Workspace.InGameFolder --Folder where ingame players are kept

local CountDownText = game.StarterGui.ScreenGui.TextLabel --Text used for round countdown and a couple other things

game.Players.PlayerAdded:Connect(function(player) --Adds player to player folder when they join
	player.CharacterAdded:Connect(function(character)
		wait()
		character.Parent = PlayerFolder
	end)
end)




function Round()
	for i,player in pairs(game.Players:GetPlayers())do --Once the round starts, all current players are put in the ingame folder
		player.Character.Parent = InGameFolder
	end
	for i,character in pairs(game.Workspace.InGameFolder:GetChildren()) do --Sends ingame folder players to the map
		character.HumanoidRootPart.Position = game.Workspace.MapSpawn.Position
	end
	CountDownText.Text = "Survive The Lava!"
	wait(5) -- Waits 5 seconds to start lava rising
	local NewLava = Instance.new("Part") --Creates a block that represents the lava
	NewLava.CanCollide = false
	NewLava.Position = Vector3.new(-6.5, -24.5, 6.5) --Positions lava under the map
	NewLava.Transparency = 0.5
	NewLava.Size = Vector3.new(200, 50, 200)
	NewLava.Anchored = true
	NewLava.Color = Color3.new(1, 0.369696, 0)
	NewLava.Material = Enum.Material.Neon
	NewLava.Parent = game.Workspace
	NewLava.Name = "Piece of Lava"
	while #InGameFolder:GetChildren() > 0 do --Keeps repeating the round until everyone is dead
		print("Round is playing")
		if #InGameFolder:GetChildren() == 0 then --If everyone dies, the script should break and the lava should be destroyed
			CountDownText.Text = "Game over!"
			print("Game over!")
			NewLava:Destroy()
			wait(3)
			break
		end
		local db = true --This is a debounce so that the lava takes health periodically
		NewLava.Touched:Connect(function(hit)
			if db then
				if hit and hit.Parent:FindFirstChild("Humanoid") then
					db = false
					hit.Parent.Humanoid.Health -= 5 --Should take 5 health every second
					wait(1)
					db = true
				end
			end
		end)
		NewLava.Position = NewLava.Position + Vector3.new(0,0.5,0) --Makes lava go up
		for i,character in pairs(game.Workspace.InGameFolder:GetChildren()) do --Sends a player back to the player folder
			if character.Humanoid.Health == 0 then
				print("You died!")
				character.Parent = PlayerFolder
			end
		end
		wait(2) --Makes lava go up every 2 seconds
	end
end

while true do --Round initiation
	wait()
	if #PlayerFolder:GetChildren() >= 1 then --If 2 people are in the game when the round is not in progress, a 10 second intermission timer should start
		print("Sufficient players!")
		local intermission = 10
		while intermission > 0 do
			CountDownText.Text = "There Are"..intermission.." Seconds Until Round Begins!"
			wait(1)
			intermission -= 1
		end
		CountDownText.Text = "Round Starting..."
		print("Round Starting...")
		wait(2)
		Round() --Should start round once the GUI says "Round Starting..."
	elseif #PlayerFolder:GetChildren() < 1 then --If less than 2 people are in the game when the round is not in progress, the GUI should display "Need 2 Players"
		CountDownText.Text =  "Waiting for players"
	end
	wait()
end
  1. GUI’s can only be edited on local scripts not server scripts

  2. Make NewLava a global variable to the script, so at the very top of the script add local NewBlock = nil, then at the start of every round you can check if NewBlock != nil then :Destroy()

  3. The :Touched function is within the loop with several different wait()s so you will have issues with the debounce and collision detection. Just take the function out of the loop or better yet put it in a different script attached to the lava.

  4. That’s just how roblox collisions works it only detects new collisions, not continuous touching. I suggest looking into Region3 and checking if there are any players in the lava region.

Hope this helps

2 Likes
NewLava.Touched:Connect(function(hit)
	if hit and hit.Parent:FindFirstChild("Humanoid") then
		if db then
			return
		end
		db = true
		hit.Parent.Humanoid.Health -= 5 --Should take 5 health every second
		wait(1)
		db = false
	end
end)

Here’s the debounce fix.

workspace:FindFirstChild("Piece of Lava"):Destroy()

This might fix destroying the lava.

while task.wait(0.5) do --every half second
	local inLava = NewLava:GetTouchingParts() --get parts touching lava
	for i, v in pairs(inLava) do --cycle through those parts
		if v.Parent:FindFirstChild("HumanoidRootPart") and v.Name == "HumanoidRootPart" then --if the part belongs to the player and is named hmr
			local hum = v.Parent:FindFirstChild("Humanoid") --declare the humanoid of the player
			hum:TakeDamage(-5) --take damage
		end
	end
end

Here’s how you could handle dealing damage to players who are in lava (even if they are standing still).

1 Like