-
I want my script to make the player be able to place down objects on their plot in a Grid. The objects will be moveable in a 2 by 2 grid.
-
When I tested out my script which is local (Still need to add the server event) it moved the part to the Mouse.Hit.Position but when I moved my mouse it would be oriented correctly (because the plots are all different orientation because of how I laid them out) but the parts / objects would not seem to move in a grid according to the plots orientation. It seemed like the moving of the part with the grid made the grid be aligned at (0, 0, 0) orientation instead of the plots orientation causing the part to move by 2 studs just not 2 studs either forward, sideways, or downwards. Because the grid makes the part move 2 in a wrong orientation the part moves smooth diagonal(or the way pointing at (0, 0,0) and moves irregular or not how it should when you move your mouse forward as seen here:
-
I looked at other forums and posted this question and no one had a clue to help direct me to fix this. Please help! I really want to release my game and without this, I can’t.
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(PlotX, PlotY, PlotZ)
Mouse.Move:Connect(MouseMoved)
end
Soil.MouseButton1Click:Connect(function()
CloneService("Soil")
end)