With my script i cannot place the block on the bottom, left and front of the block if i aim it there it will just go inside the block im aiming at
This is my code:
local gui = script.Parent
local template = gui.Frame.Area.Template
function round(num, mult)
return math.round(num / mult) * mult
end
function roundToGrid(pos)
local gridPos = Vector3.new(round(pos.X, 2), round(pos.Y, 2), round(pos.Z, 2))
return gridPos
end
for i, v in pairs(game.ReplicatedStorage.Objects:GetChildren()) do
local newButton = template:Clone()
newButton.Parent = gui.Frame.Area
newButton.Visible = true
local displayObject = v:Clone()
displayObject.Parent = newButton.ViewportFrame
newButton.MouseEnter:Connect(function()
game:GetService("TweenService"):Create(newButton, TweenInfo.new(0.1), {Size = UDim2.new(newButton.Size.X.Scale * 1.2, newButton.Size.X.Offset * 1.2, newButton.Size.Y.Scale * 1.2, newButton.Size.Y.Offset * 1.2)}):Play()
end)
newButton.MouseLeave:Connect(function()
game:GetService("TweenService"):Create(newButton, TweenInfo.new(0.1), {Size = template.Size}):Play()
end)
newButton.MouseButton1Click:Connect(function()
local mouse = game.Players.LocalPlayer:GetMouse()
local clicked = false
local newObject = v:Clone()
newObject.Parent = workspace.TemporaryParts
newObject.Transparency = 0.5
newObject.Anchored = true
newObject.CanCollide = false
mouse.Button1Down:Connect(function()
if clicked == false then
clicked = true
game.ReplicatedStorage.Events.Place:FireServer(v, newObject.Position)
newObject:Destroy()
end
end)
while clicked ~= true do
local cursorPos = mouse.Hit.Position
mouse.TargetFilter = workspace.TemporaryParts
if mouse.Target then
newObject.Position = roundToGrid(cursorPos)
print(roundToGrid(cursorPos))
end
wait()
end
end)
end
Sorry if i didnt explain it well i don’t know how to explain my problem