You can write your topic however you want, but you need to answer these questions:
-
I want my script to make it so when players build, their furniture is aligned in a grid to make it easier to build.
-
What’s happening is that the furniture isn’t moving by the grid size of two along the plot part. It aligns at the orientation of (0, 0, 0) . The plot’s orientation is (0, 140, 0) and I don’t want to make the plot orientation (0, 0, 0) I want the grid to go along with the orientation of the plot.
-
I have tried to rewrite the script multiple times. The outcome is the same when I used CFrame and now Vector3.
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Camera = game.Workspace.CurrentCamera
local BuildPro = false
local OnPlot = false
local BuildUi = script.Parent.FHOS.Frame.BuildFrame
local MarketPlaceService = game:GetService("MarketplaceService")
local RunService = game:GetService("RunService")
game.Players.PlayerAdded:Connect(function()
local hasPass = false
local success, message = pcall(function()
hasPass = MarketPlaceService:UserOwnsGamePassAsync(Player.UserId, 11321181)
end)
if not success then
warn("Error while checking if player has pass: " .. tostring(message))
return
end
if hasPass == true then
BuildPro = true
end
end)
local UIS = game:GetService("UserInputService")
local Grid = 2
local Rot = 0
local PosX
local PosY
local PosZ
local Plot
local PlotO
local PlotX
local PlotY
local PlotZ
local Object
local GivenPlot = game.ReplicatedStorage.BuildEvents.GivenPlot
local PlaceObject = game.ReplicatedStorage.BuildEvents.PlaceObject
GivenPlot.OnClientEvent:Connect(function(plt)
Plot = plt
PlotO = plt.Orientation
PlotX = PlotO.X
PlotY = PlotO.Y
PlotZ = PlotO.Z
end)
Plot.Touched:Connect(function(hit)
local plr = game:GetService("Players"):GetPlayerFromCharacter(hit.Parent)
if plr then
OnPlot = true
end
end)
local CanStart = true
local Placing = nil
local CanPlace = nil
local MoveObject = false
local CanPlace
local BuildMode = Instance.new("BoolValue")
BuildMode.Parent = Player
BuildMode = false
BuildSelection = BuildUi.ScrollingFrame
Soil = BuildSelection.SoilSelect.ImageButton
script.Parent.FHOS.Frame.Frame.BuildModeApp.TextButton.MouseButton1Click:Connect(function()
script.Parent.FHOS.Frame.Frame.Visible = false
script.Parent.FHOS.Frame.FhBrand.Visible = false
script.Parent.FHOS.Frame.Power.Visible = false
script.Parent.FHOS.Frame.Time.Visible = false
script.Parent.FHOS.Frame.Network.Visible = false
script.Parent.FHOS.Frame.Battery.Visible = false
script.Parent.FHOS:TweenPosition(UDim2.new(0.105, 0,0.485, 0), "Out", "Linear", 1, false, nil)
while script.Parent.FHOS.Rotation > -90 do
script.Parent.FHOS.Rotation = script.Parent.FHOS.Rotation - 1
wait()
end
BuildMode = true
if BuildMode == true and OnPlot == true or BuildPro == true then
Camera.CameraSubject = Plot
end
end)
local function SnapToGrid()
PosX, PosY, PosZ = math.floor(Mouse.Hit.X / Grid + .5) * Grid, math.floor(Mouse.Hit.Y / Grid + 1) * Grid, math.floor(Mouse.Hit.Z / Grid + .5) * Grid
end
local function MouseMoved()
Object.PrimaryPart.Position = Vector3.new(PosX, PosY, PosZ)
SnapToGrid()
end
local function CloneService(Obj)
Object = game.ReplicatedStorage.BuildObjects:FindFirstChild(Obj):Clone()
Object.Parent = Plot
Object.PrimaryPart.Orientation = Vector3.new(0, PlotY, 0)
Mouse.Move:Connect(MouseMoved)
end
Soil.MouseButton1Click:Connect(function()
CloneService("Soil")
end)