My part of my script here is supposed to use a gridsize of 2 and it is oriented correctly but when you move the part it out aligns the part with the grid on the floor is there a way to make the part aligned with a vector?? or Cframe??? Please help if you can!
local RunService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Mouse = Player:GetMouse()
local Camera = workspace.CurrentCamera
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject
local GivenPlot = game.ReplicatedStorage.BuildEvents.GivenPlot
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject
local posX
local posY
local posZ
local YPos = Vector3.new(0, 75, 0)
local Rot = 0
local Object
local Plot
local PlotO
local ButtonObject = script.Parent.ScrollingFrame.Soil.ImageButton
local CanStart = true
IsPlacing = nil
local CanPlace = nil
GivenPlot.OnClientEvent:Connect(function(plt)
Plot = plt.Name
pltPX = plt.Position.X
pltPY = plt.Position.Y
pltPZ = plt.Position.Z
PlotO = plt.Orientation
PlotX = PlotO.X
PlotY = PlotO.Y
PlotZ = PlotO.Z
end)
local function Placement()
if IsPlacing and CanPlace then
PlaceObject:FireServer(posX, posY, posZ, Rot, Object.Name, PlotX, PlotY, PlotZ)
IsPlacing = false
CanPlace = false
CanStart = true
Object:Destroy()
end
end
local function TopDownView()
if IsPlacing then
local playerPos = Char:FindFirstChild("HumanoidRootPart").Position
local cameraPos = playerPos + YPos
Camera.CFrame = CFrame.new(cameraPos, playerPos)
end
end
local function Movement()
if IsPlacing and CanPlace and not CanStart and Mouse.Target and Mouse.Target.Name == Plot then
Mouse.TargetFilter = Object
posX = math.floor(Mouse.Hit.X / 2 + 0.5)*2
posY = math.floor(Mouse.Hit.Y / 2 + 0.5)*2 - 1
posZ = math.floor(Mouse.Hit.Z / 2 + 0.5)*2
Object:SetPrimaryPartCFrame(Object.PrimaryPart.CFrame:Lerp(CFrame.new(posX, posY, posZ) * CFrame.Angles(0, math.rad(Rot), 0), 0.2))
Object.PrimaryPart.Orientation = (Vector3.new(PlotX, PlotY, PlotZ))
else
return Mouse.Hit.p
end
end
local function StartPlacementSoil()
if CanStart then
Object = game:GetService("ReplicatedStorage").Soil:Clone()
Object.Parent = workspace
Mouse.Move:Connect(Movement)
IsPlacing = true
CanPlace = true
CanStart = false
Mouse.Move:Connect(Movement)
end
end
local function StartPlacement(obj)
if CanStart then
Object = game.ReplicatedStorage:FindFirstChild(obj):Clone()
Object.Parent = workspace
IsPlacing = true
CanPlace = true
CanStart = false
end
end
local function Rotation(input, GPE)
if IsPlacing and CanPlace and not CanStart and input.KeyCode == Enum.KeyCode.R then
Rot = Rot + 90
Object:SetPrimaryPartCFrame(Object.PrimaryPart.CFrame * CFrame.Angles(0, math.rad(Rot), 0))
end
end
Mouse.Button1Down:Connect(Placement)
ButtonObject.MouseButton1Click:Connect(function()
StartPlacement("Soil")
end)
RunService:BindToRenderStep("Input", Enum.RenderPriority.Input.Value, Movement)
UIS.InputBegan:Connect(Rotation)
