-- 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
#Part spreading script in all directions
1 messages · Page 1 of 1 (latest)
no errors just doesn't spread in all directions
What does it do when you run it, then? Does it create parts and it just doesn't offset them or what
this too lol
it's complicated to explain all of it in text. it's probably easier to just run the script in studio yourself. all you have to do is paste the code in a script and put the script inside a part that has size 3,3,3
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
I'll look into it in some hours
Ok
can you build the concept with your hand
I'm unsure what you trying to do
Supposed to clone the part right?
Later I'll try to find the code error
it also go down right?
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
yes, i did that and the result is the script above. i need help fixing the script because it doesn't behave as intended
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?
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)
later cuz i eating
It's weird to use task.spawn in this situation
you’re checking if the raycast result is nil
nevermind, I forgot thats what you want
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
@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
ahh yes it will work 100% how you want
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)))
just to give him a general idea of how to do it
i just realized i missed the "not"
i meant to say "it will probably not work 100% like you want"
lmao
😂
lol, ty
no problem, but remember you'll probably have to modify this to make it work like you want to