Flood Script not hurting player anymore when water reaches the top

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m making a flood weather event for my game.

  2. What is the issue? Include screenshots / videos if possible!
    When the water reaches the top, it no longer damages the player.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried AI to fix it, and I’ve tried looking at other dev forum posts but none of them really seem to match the issue I have.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

-- Script to control the flood event
local floodWater = game.Workspace:WaitForChild("FloodWater")
local riseSpeed = 0.5 -- Speed at which the floodWater rises
local maxFloodHeight = 75 -- Maximum height the floodWater will reach

-- Ensure the floodWater part is invisible and non-collidable
floodWater.Transparency = 0
floodWater.CanCollide = false

-- Function to handle parts touched by the floodWater part
local function handleTouch(part)
	-- Check if the touched part is below the current floodWater level
	if part.Position.Y <= floodWater.Position.Y + floodWater.Size.Y / 2 then
		-- Check if the part is a player
		local character = part.Parent
		local humanoid = character:FindFirstChildOfClass("Humanoid")

		if humanoid then
			-- Damage the player
			humanoid.Health = humanoid.Health - 1 -- Adjust the damage as needed
		else
			-- Break joints of non-immune parts
			if not part:GetAttribute("IsImmune") then
				part:BreakJoints()
			end
		end
	end
end

-- Connect the touch event for floodWater
floodWater.Touched:Connect(handleTouch)

-- Function to start the flood event
local function startFlood()
	local initialSize = floodWater.Size
	local initialPosition = floodWater.Position
	local floodWaterLevel = initialPosition.Y

	while floodWaterLevel < maxFloodHeight do
		-- Increase the size of the floodWater part
		floodWater.Size = floodWater.Size + Vector3.new(0, riseSpeed, 0)

		-- Adjust the position to ensure the water rises properly
		floodWater.Position = floodWater.Position + Vector3.new(0, riseSpeed / 2, 0)

		-- Update the flood water level
		floodWaterLevel = floodWater.Position.Y + floodWater.Size.Y / 2

		-- Define the flood area
		local floodAreaCFrame = floodWater.CFrame
		local floodAreaSize = floodWater.Size

		-- Fill the terrain with water
		game.Workspace.Terrain:FillBlock(floodAreaCFrame, floodAreaSize, Enum.Material.Water)

		wait(0.1)
	end
end

-- Start the flood event
startFlood()

This is a screenshot of the water at the top without the flood water part transparent.

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

3 Likes

Opps I did not realize I written that part in the code also.

2 Likes

Instead of using the .Touched event to detect players, you should use :GetPartsInBoundBox in a loop, as .Touched is very exploitable and only works when a player stops making contact with the part and then makes contact again.

2 Likes

Okay I’ll try that. Thanks for the reply!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.