#Part spreading script in all directions

1 messages · Page 1 of 1 (latest)

worldly charm
#

-- This script is supposed to create a part to the left, right, forward, backward, and under the origin part if there isn't a part already there within 3 studs. It's not working as intended (see picture). I've attached the script to this post. Please help. You can replicate this by taking the script and pasting it into a 3x3 sized part

viscid trout
#

no errors?

#

print all your raycastResult variables and see if they're all nil

worldly charm
#

no errors just doesn't spread in all directions

viscid trout
#

What does it do when you run it, then? Does it create parts and it just doesn't offset them or what

worldly charm
#

it does create a lot of parts that aren't where they're supposed to be - lots of parts being positioned in places where there's already a part

viscid trout
#

I'll look into it in some hours

worldly charm
#

Ok

steep lagoon
#

I'm unsure what you trying to do

steep lagoon
#

Later I'll try to find the code error

worldly charm
#

it's supposed to spread like water in minecraft

steep lagoon
#

ok

worldly charm
#

yeah

#

so the water spreads in all directions

#

except diagnolly

steep lagoon
#

it also go down right?

worldly charm
#

rn it looks like this #1099377635844431962 message

#

yeah

zinc vigil
#

You gotta break down what you want into small parts so it’s easier to think about how you can make it work

#

So what you want here is basically a block that behaves like minecraft

#

I’m not sure if it’s 100% related but you could look a bit into ”Cellular automaton”

#

So you have a base water block

#

And each update sequence it will spread 1 block

worldly charm
#

yes, i did that and the result is the script above. i need help fixing the script because it doesn't behave as intended

zinc vigil
#

I’m on phone so I can’t really take a look at it

#

Do you think you could send it as formatted text or take a picture of it?

worldly charm
#

local block_size = 3

function spread(origin)
local liquid_origin_part = origin
local rayOrigin = liquid_origin_part.Position

local forwardRayDirection = liquid_origin_part.cFrame.lookVector * 3
local backwardRayDirection = -(liquid_origin_part.cFrame.lookVector * 3)
local rightRayDirection = liquid_origin_part.cFrame.rightVector * 3
local leftRayDirection = -(liquid_origin_part.cFrame.rightVector * 3)
local downRayDirection = -(liquid_origin_part.cFrame.upVector * 3)

local raycastResult_one = workspace:Raycast(rayOrigin, forwardRayDirection)
local raycastResult_two = workspace:Raycast(rayOrigin, backwardRayDirection)
local raycastResult_three = workspace:Raycast(rayOrigin, rightRayDirection)
local raycastResult_four = workspace:Raycast(rayOrigin, leftRayDirection)
local raycastResult_five = workspace:Raycast(rayOrigin, downRayDirection)

wait(.1)

task.spawn(function()
    if raycastResult_one == nil then
        local block = Instance.new("Part")
        block.Name = "Tile"
        block.Size = Vector3.new(block_size, block_size, block_size)
        block.Position = rayOrigin + Vector3.new(0, 0, 3)
        block.Anchored = true
        block.Name = "Forward"
        block.Parent = game.Workspace

        spread(block)
    end
end)

wait(.1)

task.spawn(function()
    if raycastResult_two == nil then
        local block = Instance.new("Part")
        block.Name = "Tile"
        block.Size = Vector3.new(block_size, block_size, block_size)
        block.Position = rayOrigin + Vector3.new(0, 0, -3)
        block.Anchored = true
        block.Name = "Back"
        block.Parent = game.Workspace
#

spread(block)
end
end)

wait(.1)

task.spawn(function()
    if raycastResult_three == nil then
        local block = Instance.new("Part")
        block.Name = "Tile"
        block.Size = Vector3.new(block_size, block_size, block_size)
        block.Position = rayOrigin + Vector3.new(3, 0, 0)
        block.Anchored = true
        block.Name = "Right"
        block.Parent = game.Workspace

        spread(block)
    end
end)

wait(.1)

task.spawn(function()
    if raycastResult_four == nil then
        local block = Instance.new("Part")
        block.Name = "Tile"
        block.Size = Vector3.new(block_size, block_size, block_size)
        block.Position = rayOrigin + Vector3.new(-3, 0, 0)
        block.Anchored = true
        block.Name = "Left"
        block.Parent = game.Workspace

        spread(block)
    end
end)

wait(.1)

task.spawn(function()
    if raycastResult_five == nil then
        local block = Instance.new("Part")
        block.Name = "Tile"
        block.Size = Vector3.new(block_size, block_size, block_size)
        block.Position = rayOrigin + Vector3.new(0, -3, 0)
        block.Anchored = true
        block.Name = "Down"
        block.Parent = game.Workspace

        spread(block)
    end
end)

return

end

spread(script.Parent)

steep lagoon
#

wait

#

I forget to send it here

steep lagoon
steep lagoon
zinc vigil
#

nevermind, I forgot thats what you want

worldly charm
#

i chose to use task.spawn so it looks like the water is spreading in all directions simulataneously as opposed to one direction at a time

zinc vigil
#

@worldly charm I threw together something based on what you told us

#

but beware

#

it will probably not work 100% like you want

#

so you'll have to modify it

viscid trout
#

ahh yes it will work 100% how you want

zinc vigil
#
local BlockSize = 2

local Directions = {
    
    Vector3.new(1, 0, 0),
    Vector3.new(-1, 0, 0),
    Vector3.new(0, 0, 1),
    Vector3.new(0, 0, -1),
    Vector3.new(0, -1, 0)
    
}

local function CreateBlock(position)
    
    local x = math.floor(position.X / BlockSize) * BlockSize
    local y = math.floor(position.Y / BlockSize) * BlockSize
    local z = math.floor(position.Z / BlockSize) * BlockSize
    
    local part = Instance.new("Part")
    part.Size = Vector3.new(1, 1, 1) * BlockSize
    part.Position = Vector3.new(x, y, z)
    part.CanCollide = false
    part.Anchored = true
    part.Parent = workspace
    
    return part
    
end

local function Spread(block)
    
    coroutine.wrap(function()
        
        wait(1)
        
        local params = RaycastParams.new()
        params.FilterType = Enum.RaycastFilterType.Blacklist
        params.FilterDescendantsInstances = {block}
        
        for _, direction in ipairs(Directions) do
            
            local raycast = workspace:Raycast(block.Position, direction * BlockSize, params)
            
            if not raycast then
                
                Spread(CreateBlock(block.Position + direction * BlockSize))
                
            end
            
        end
        
    end)()
    
end

Spread(CreateBlock(Vector3.new(0, 10, 0)))
zinc vigil
zinc vigil
#

i meant to say "it will probably not work 100% like you want"

viscid trout
#

lmao

zinc vigil
#

😂

worldly charm
#

lol, ty

zinc vigil