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

Can anyone help with this Grid Alignment Problem?, It's Aim Is Off By 1 Block [SOLVED]

Asked by 7 years ago
Edited 7 years ago

So RubenKan Did Help Me A Bit But Then There Still Was The Problem So Here Is The Current Code:

local mouse = game:GetService('Players').LocalPlayer:GetMouse()
local HotbarItems = {'Grass','Stone','Bricks','Sand','WoolRed','MoltenRock','Netherrack','Water','Lava','Gravel'}
local ItemList = {'Grass','Dirt','Stone','Bedrock','DiamondOre','CopperOre','IronOre','EmeraldOre','GoldOre','RedstoneOre','MoltenRock','Bricks','Leaves','WoolDarkGray','WoolOrange','WoolGray','WoolBrown','WoolDarkGreen','WoolLightGreen','WoolGreen','WoolBlue','WoolLightBlue','WoolLightYellow','SpruceWood','OakWood','DarkOakWood','AcaciaWood','AcaciaWoodPlanks','DarkOakWoodPlanks','OakWoodPlanks','SpruceWoodPlanks','Concrete','Cobblestone','Sand','Gravel','Netherrack','WoolRed','Water','Lava'}
local Selected = 1

mouse.Button1Down:connect(function()
    local target = mouse.Target
    for index, value in ipairs(ItemList) do
    if target.Name == value then
    target:Destroy()
end
end
end)

mouse.Button2Down:connect(function()
    local PlacedObjectIdentifier = HotbarItems[Selected]
    local ClonedBlock = game:GetService('Lighting'):FindFirstChild(PlacedObjectIdentifier):Clone()

    ClonedBlock.Parent = game:GetService('Workspace')
    local p=mouse.Hit.p
    local x,y,z = p.x,p.y,p.z

-- Added stuff
    xdif = math.floor(x/4)*4 -- Grids positions X value (0,4,8,12,16 etc)
    ydif = math.floor(y/4)*4 -- Grids positions Y value (0,4,8,12,16 etc)
    zdif = math.floor(z/4)*4 -- Grids positions Z value (0,4,8,12,16 etc)

    ClonedBlock.CFrame = CFrame.new(xdif,ydif,zdif)

end)


mouse.KeyDown:connect(function(key)
    if key == '1' then
        Selected = 1
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot1.Position))
    elseif key == '2' then
        Selected = 2
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot2.Position))
    elseif key == '3' then
        Selected = 3
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot3.Position))
    elseif key == '4' then
        Selected = 4
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot4.Position))
    elseif key == '5' then
        Selected = 5
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot5.Position))
    elseif key == '6' then
        Selected = 6
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot6.Position))
    elseif key == '7' then
        Selected = 7
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot7.Position))
    elseif key == '8' then
        Selected = 8
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot8.Position))
    elseif key == '9' then
        Selected = 9
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot9.Position))
    elseif key == '0' then
        Selected = 10
        script.Parent.Selector:TweenPosition(UDim2.new(script.Parent.Slot10.Position))
    end
end)

And Here Is The Place You Can See It Function In: https://web.roblox.com/games/588166455/Universal-Worlds

Answer this question