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

Why wont this script work? (URGENT) places blocks on the front top and rights sides of a block

Asked by 2 years ago

This script is meant to place blocks on a 3d grid by rounding. BUT it only works on the top right and front Faces. ANY other faces will result in it placing the block inside the original.

local Mouse = game.Players.LocalPlayer:GetMouse()
local Positiona
local bloc
local pos
local X
local Y
local Z
local lasserx
local lassery
local lasserz

script.Parent.Activated:Connect(function()

    script.Parent.place:FireServer(Positiona, bloc, pos)
    bloc = script.Parent:GetAttribute("block")
    pos = Mouse.Target
end)

Mouse.Move:Connect(function() -- NEW PLACEMENT SYSTEM
    local GridSize = 4
    if Mouse.TargetSurface.Name == "Top" or "Right" or "Front" then
         X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
         Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 1.5
        Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
        lasserx = false
        lassery = false
        lasserz = false
    elseif Mouse.TargetSurface.Name == "Bottom" then
        X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
        Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 1.5
        Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
        lasserx = false
        lassery = true
        lasserz = false
    elseif Mouse.TargetSurface.Name == "Left" then
        X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
        Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 1.5
        Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
        lasserx = true
        lassery = false
        lasserz = false
    elseif Mouse.TargetSurface.Name == "Back" then
        X = math.floor((Mouse.Hit.X + GridSize / 2) / GridSize) * GridSize
        Y = math.ceil((Mouse.Hit.Y + GridSize / 4 ) / GridSize) * GridSize - 1.5
        Z = math.floor((Mouse.Hit.Z + GridSize / 2) / GridSize) * GridSize
        lasserx = false
        lassery = false
        lasserz = true
    end

    if lasserx == true then
        Positiona = CFrame.new(X - 1, Y, Z)
    elseif lassery == true then
        Positiona = CFrame.new(X, Y - 1, Z)
    elseif lasserz == true then
        Positiona = CFrame.new(X, Y, Z - 1)
    else
        Positiona = CFrame.new(X, Y, Z)
        end

end)

Answer this question