Hello, So I got a placement system and I need help to make it a grid placement system I have tried a lot of way but all failing.
the gird needs to be 4,4,4 any help is really wanted.
Local script
local placementEvent = game.ReplicatedStorage.PlacementEvent
local ObjectFolder = game.ReplicatedStorage:WaitForChild("ObjectFolder")
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 RotatingObject = 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 = false
local RotatingAmount = 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
RotatingObject = true
while RotatingObject == 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
RotatingObject = false
end
end)
RunService.RenderStepped:Connect(function()
if PlacingObject == true then
mouse.TargetFilter = PrevieuwObject
if PrevieuwObject:FindFirstChild("MainPart") then
local ObjectCFrame = CFrame.new(mouse.Hit.Position.X, mouse.Hit.Position.Y + PrevieuwObject.PrimaryPart.Size.Y / 2, mouse.Hit.Position.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("ObjectFolder")
PlacementEvent.OnServerEvent:Connect(function(Player, PreviewObject, ObjectCFrame)
local Object = ObjectFolder:FindFirstChild(PreviewObject):Clone()
Object:SetPrimaryPartCFrame(ObjectCFrame)
Object.Parent = game.Workspace
end)