local RS = game:GetService("RunService")
local terrain = workspace.Terrain
local REGIONS = {}
for i,v in pairs(game.Workspace.AntiWater:GetChildren()) do
local antiwaterregion = Region3.new(v.Position+Vector3.new(v.Position.X/2,v.Position.Y/2,v.Position.Z/2),v.Position-Vector3.new(v.Position.X/2,v.Position.Y/2,v.Position.Z/2))
table.insert(REGIONS,antiwaterregion)
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
while wait(2) do
for i,v in pairs(REGIONS) do
terrain:ReplaceMaterial(v,4,Enum.Material.Water,Enum.Material.Air)
end
end
end)
end)
for some reason, the script makes the game unplayable. it doesnt even load. here are pictures of the explorer:
btw i have tried changing the part size to very small, and it looks like thats not the problem
It is unclear what is happening due to the lack of context. I would recommend providing the .rblx file before this post gets buried deep into the world of unanswered forums.
So i made a script which basically generates water on the players X and Z position on the ocean level every 2 seconds. its working fine, but there are some places which shouldnt have water in it, so i made a folder in the workspace with parts which shouldnt have water in it. Currently there is only 1 part there, however when i try to clear the water from this region it crashes. heres the full script
local RS = game:GetService("RunService")
local terrain = workspace.Terrain
local REGIONS = {}
for i,v in pairs(game.Workspace.AntiWater:GetChildren()) do
local antiwaterregion = Region3.new(v.Position+Vector3.new(v.Position.X/2,v.Position.Y/2,v.Position.Z/2),v.Position-Vector3.new(v.Position.X/2,v.Position.Y/2,v.Position.Z/2))
table.insert(REGIONS,antiwaterregion)
end
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function()
local oldregion
while wait(2) do
local char = plr.Character
local hrp = char.PrimaryPart
local middle = Vector3.new(hrp.Position.X,237.313,hrp.Position.Z)
local cylregion = Region3.new(middle-Vector3.new(500,19,500),middle+Vector3.new(500,19,500))
if oldregion ~= nil then
terrain:ReplaceMaterial(oldregion,4,Enum.Material.Water,Enum.Material.Air)
end
terrain:ReplaceMaterial(cylregion,4,Enum.Material.Air,Enum.Material.Water)
oldregion = cylregion
for i,v in pairs(REGIONS) do
terrain:ReplaceMaterial(v,4,Enum.Material.Water,Enum.Material.Air)
end
end
end)
end)
local antiwaterregion = Region3.new(v.Position+Vector3.new(v.Position.X/2,v.Position.Y/2,v.Position.Z/2),v.Position-Vector3.new(v.Position.X/2,v.Position.Y/2,v.Position.Z/2))
instead of doing v.Position.X/2 etc… i should be doing v.Size.X/2.
local antiwaterregion = Region3.new(v.Position+Vector3.new(v.Size.X/2,v.Size.Y/2,v.Size.Z/2),v.Position-Vector3.new(v.Size.X/2,v.Size.Y/2,v.Size.Z/2))