Ad
Log in to vote
0

How do I add Vector3 to Region3?

Asked by 2 months ago

I'm working on a game where random disasters are generated through a module script, and I'm currently making a flood. However, since the touch event isn't quite the best for this, I am considering region3. I want to make the size of the region3 rise every 2 seconds, however, I can't seem to add a Vector3 to the Region3. I have one error in the output.

Disasters (Module script):

> local TweenService = game:GetService("TweenService")
> local RoundEnded = game.ReplicatedStorage.RoundEnded
> local Disaster = {}
> Disaster.__index = Disaster
> 
> function Disaster.new(DisasterType)
>   local self = {}
>   setmetatable(self, Disaster)
>   self.DisasterType = DisasterType
>   
>   
>   if self.DisasterType == "Flood" then
>       local floodRegion = Region3.new(workspace.Baseplate.Position - (workspace.Baseplate.Size/2), workspace.Baseplate.Position + (workspace.Baseplate.Size/2))
>       self.Flood = Instance.new("Part")
>       self.Flood.Position = workspace.Baseplate.Position + Vector3.new(0,0.5,0)
>       self.Flood.Size = floodRegion.Size
>       self.Flood.Name = "Flood"
>       self.Flood.Anchored = true
>       self.Flood.CanCollide = false
>       self.Flood.Transparency = 1
>       self.Flood.Parent = workspace
>           
>       for round = 30, 1, -1 do
>           floodRegion.Size += Vector3.new(0,1,0)
>           self.Flood.Size = floodRegion.Size
>           workspace.Terrain:FillBlock(self.Flood.CFrame, self.Flood.Size, Enum.Material.Water)
>           if self.Flood.Size.X > 18 then
>               print("1")
>           end
>           wait(2)
>       end
>       
>   end
>   return self
> end
> 
> function Disaster:GetDisaster()
>   local disasters = {"Flood"}
>   local rng = math.random(1,#disasters)
>   
>   if rng == 1 then
>       Disaster.new(disasters[1])
>       return disasters[1]
>   end
>   
>   return disasters
> end
> 
> function Disaster:RemoveDisaster()
>   self.Parent = nil
> end
> 
> return Disaster
> 

Error message:

Size cannot be assigned to - Server - Disasters:24

As always, thank you for your time and I appreciate any help.

1 answer

Log in to vote
0
Answered by 1 month ago
Edited 1 month ago

I don't know if there's a better way to do it other than to apply the size to the "flood" part and recalculate the region. Keep on trying to find better info tho, as I do not know if this is the best way to do it.

 local floodRegion = Region3.new(workspace.Baseplate.Position -     (workspace.Baseplate.Size/2), workspace.Baseplate.Position + (workspace.Baseplate.Size/2))
    self.Flood = Instance.new("Part")
     self.Flood.Position = workspace.Baseplate.Position + Vector3.new(0,0.5,0)
    self.Flood.Size = floodRegion.Size
    self.Flood.Name = "Flood"
    self.Flood.Anchored = true
     self.Flood.CanCollide = false
    self.Flood.Transparency = 1
    self.Flood.Parent = workspace

    for round = 30, 1, -1 do
        self.Flood.Size += Vector3.new(0, 1, 0)
        self.Flood.Position += Vector3.new(0, 0.5, 0)

        floodRegion = Region3.new(workspace.Baseplate.Position -    (workspace.Baseplate.Size/2), workspace.Baseplate.Position + (workspace.Baseplate.Size/2))
        workspace.Terrain:FillBlock(self.Flood.CFrame, self.Flood.Size,           Enum.Material.Water) if self.Flood.Size.X > 18 then
        print("1")
    end
    wait(2)

Please let me know if this works properly, as I haven't tested it.

Hopefully I helped as much as I could.

0
I definetly think there's a better way to do this however, because recalculating region3 every second sounds a bit unoptimised. robert19735 17 — 1mo
Ad

Answer this question