So i am making a block creation and breaking script but when the block places it is placed on the grid i have but it creates it like 1 block next to the mouse Here is the 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
ClonedBlock.CFrame = CFrame.new(x-x%4,y-y%4,z-z%4)
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)

11 comments
Can you give a little explanation of what each piece does?
Also i realised that i wrote the version of the script that had the actual code commented out
i just fixed that
Last thing, how do i set the block's position to what this returns?
If this helped, Please accept and upvote this awnser. :D -Happy hollidays!
I cant upvote because i dont have 25 rep but i would if i could and also, how do i create the block next to or on top of another block if the player clicks on top or the side or under it?
Suggest making each block 4.001,4.001,4.001 wide, Thats what i did in my game.
ok, also i accidentally managed to mess up some unions and now they show as nothing, any way i can fix that?
Try seperating them and modeling them again
it came up with "Error 64-Bit Coding Could not be found" or something like that
It is also still out of Aim a bit check it out here: https://web.roblox.com/games/588166455/Universal-Worlds