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
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
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