Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I need help with a grid building system?

Asked by 3 years ago

So I was using this video to make a a block placement system: https://www.youtube.com/watch?v=x1YmQNzf5dQ

The code is here

local snap = 3


game.ReplicatedStorage:WaitForChild("PlaceBlockRE").OnServerEvent:Connect(function(plr, blockType, target, targetSurface, removeOrPlace)


    if removeOrPlace == "placing" then

        local position

        if targetSurface == Enum.NormalId.Top then
            position = target.Position + Vector3.new(0, snap, 0)

        elseif targetSurface == Enum.NormalId.Bottom then
            position = target.Position - Vector3.new(0, snap, 0)

        elseif targetSurface == Enum.NormalId.Left then
            position = target.Position - Vector3.new(snap, 0, 0)

        elseif targetSurface == Enum.NormalId.Right then
            position = target.Position + Vector3.new(snap, 0, 0)

        elseif targetSurface == Enum.NormalId.Front then
            position = target.Position - Vector3.new(0, 0, snap)

        elseif targetSurface == Enum.NormalId.Back then
            position = target.Position + Vector3.new(0, 0, snap)
        end


        local blockInPos

        for i, d in pairs(workspace:GetDescendants()) do

            if d:IsA("BasePart") and d.Position == position then blockInPos = true end
        end


        if not blockInPos and position then

            local newBlock = blockType:Clone()
            newBlock.Size = Vector3.new(snap, snap, snap)
            newBlock.Anchored = true

            newBlock.Position = position

            newBlock.Parent = workspace

            game.ReplicatedStorage.PlaySoundRE:FireClient(plr)
        end


    elseif removeOrPlace == "removing" then

        if target and target:FindFirstChild("Placeable") then
            target:Destroy()

            game.ReplicatedStorage.PlaySoundRE:FireClient(plr)
        end
    end
end)



local gridX, gridZ = 100, 100


for x = 1, gridX do

    for z = 1, gridZ do


        local block = game.ReplicatedStorage.Blocks.Grass:Clone()
        block.Size = Vector3.new(snap, snap, snap)
        block.Anchored = true

        block.Position = Vector3.new(snap * x, snap, snap * z)

        block.Parent = workspace
    end
end

I want to be able to place a block I am not directly looking at, but will still be connected to another block when placed. Does anyone know how to do this?

0
I've been trying to do the same thing for a while. It's really annoying the crap me and I cannot get anywhere. Voltaicmimic 43 — 3y
0
Its so annoying because no ones responding :( yousupertrashy 5 — 3y

Answer this question