How do I return terrain back to its original setting?

I have a Region3 script that when you enter the part, it changes the water size. When the player leaves the region I want the water size to change from 0 to .2. How do I do it?

local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local Region = Region3.new(pos1, pos2)
local Terrain = game.Workspace.Terrain

while true do
	wait()
	local partsInRegion = workspace:FindPartsInRegion3(Region, nil, 1000)
	for i, part in pairs(partsInRegion) do
		if part.Parent:FindFirstChild("Humanoid") ~= nil then
			Terrain.WaterWaveSize = 0
			
			end
		end
	end
end
1 Like

Does this small change work for you?

No, It prevents the Water Wave size not being able to be changed at all.

1 Like

Are you sure that there aren’t non player objects within the area that has humanoid (for any reason)? Or that they have an object named “Humanoid” but is actually not a humanoid?

Try this code:

local PlayerExists = false
for i, part in pairs(partsInRegion) do
	if game.Players:GetPlayerFromCharacter(part.Parent) then	
        PlayerExists = true
        break
	end
end

if PlayerExists == true then
    Terrain.WaterWaveSize = 0.2
else
    Terrain.WaterWaveSize = 0
end

What part of the script would I put this?

It is meant to be under the while true do loop

(partsInRegion) has an error. ,

well why didn’t you mention it from the start,
it literally cannot be a new error caused I changed nothing at the top

did you delete your pathsinregion variable??

No, do you want to see the script I have with the changes?

yes I do

111111111111111111111111111111111111111111

local RegionPart = game.Workspace.RegionPart
local pos1 = RegionPart.Position - (RegionPart.Size / 2)
local pos2 = RegionPart.Position + (RegionPart.Size / 2)
local Region = Region3.new(pos1, pos2)
local Terrain = game.Workspace.Terrain

while true do
	wait()
	local partsInRegion = workspace:FindPartsInRegion3(Region, nil, 1000)
	local PlayerExists = false
	for i, part in pairs(partsInRegion) do
		if game.Players:GetPlayerFromCharacter(part.Parent) then	
			PlayerExists = true
			break
		end
	end

	if PlayerExists == true then
		Terrain.WaterWaveSize = 0.2
	else
		Terrain.WaterWaveSize = 0
	end
		end

ok what kind of error did you get? copy paste

I’m not getting an error anymore, but the water isn’t changing.

spam print statements within your code. that’s my debugging method. works literally 100% of the time.

if all prints out, the problem is MOST LIKELY not within the script

add a print statement at every line of the code…

Everything was printed, so what could be the issue?

ensure that when testing, you’re within the region part.

is this a local script, or a server sided script?

you might want to do print(Region), or print(partsInRegion)

Its a external issue maybe from another script or perhaps Roblox it self.

It’s a server-side script.


Do I do this for every line of code, or where would it go?

right below the variable itself