Hello, so I have been working on a grid placement system this past week and keep having problems I have had some help from the devfourm but I am still having problems.
my problem is that move a block on the Y axis it doesnt snap to the grid and lets me go free for all with movment but when I go on X or Z it snaps back to grid.
I also keep having the problem where i can place a block inside another block and i dont know how to fix this.
I want it that if I try to place a block where a block already is the privew block turns red and doesnt let me place it.
Here is my script.
Local script.
local placementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("PlacementFolder")
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local mouse = player:GetMouse()
local Frame = script.Parent:WaitForChild("Frame")
local UserImputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local PlacingObject = false
local RotatingObjectR = false
local RotatingObjectT = false
local RotatingObjectY = false
local RotatingObjectCoolDown = false
for i, Button in pairs(Frame:GetChildren()) do
if Button:IsA("TextButton") then
Button.MouseButton1Click:Connect(function()
if PlacingObject == false then
PlacingObject = true
Frame.Visible = true
local RotatingAmount = 0
local RotatingAmountT = 0
local RotatingAmountY = 0
local PrevieuwObject = ObjectFolder:FindFirstChild(Button.Name):Clone()
PrevieuwObject.Parent = game.Workspace
for i, Parts in pairs(PrevieuwObject:GetDescendants()) do
if Parts:IsA("BasePart") then
Parts.Transparency = 0.5
Parts.CanCollide = false
end
end
UserImputService.InputBegan:Connect(function(Key, GameProcessed)
if not GameProcessed then
if not RotatingObjectCoolDown then
if Key.KeyCode == Enum.KeyCode.R then
RotatingObjectR = true
while RotatingObjectR == true do
wait()
RotatingAmount += 90
RotatingObjectCoolDown = true
wait(0.1)
RotatingObjectCoolDown = false
end
end
end
end
end)
UserImputService.InputEnded:Connect(function(Key)
if Key.KeyCode == Enum.KeyCode.R then
RotatingObjectR = false
end
end)
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
mouse.TargetFilter = PrevieuwObject
if PrevieuwObject:FindFirstChild("MainPart") then
local x = math.floor(mouse.Hit.Position.X / 2) * 2
local y = mouse.Hit.Position.Y + PrevieuwObject.PrimaryPart.Size.Y / 2 or math.floor(mouse.Hit.Position.Y / 2) * 2
local z = math.floor(mouse.Hit.Position.Z / 2) * 2
local ObjectCFrame = CFrame.new(x, y, z)
local ObjectAngles = CFrame.Angles(0, math.rad(RotatingAmount), 0)
PrevieuwObject:SetPrimaryPartCFrame(ObjectCFrame * ObjectAngles)
end
end
end)
mouse.Button1Up:Connect(function()
if PlacingObject == true then
PlacingObject = false
placementEvent:FireServer(PrevieuwObject.Name, PrevieuwObject.PrimaryPart.CFrame)
Frame.Visible = true
PrevieuwObject:Destroy()
end
end)
end
end)
end
end
Server script
local PlacementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("PlacementFolder")
PlacementEvent.OnServerEvent:Connect(function(Player, PreviewObject, ObjectCFrame)
local Object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
Object:SetPrimaryPartCFrame(ObjectCFrame)
Object.Parent = game.Workspace
end)
Help is greatly wanted and thanks for reading.