Hey! So im trying to make an game similar to Obby Creator, but instead of just obbies, you can build whatever you want with an editor similar to roblox studio’s, and im currently working on the placement system
i already got some of the script done but i dont know how to make the parts snap to what part your cursor is, like in the video shown below:
Heres my current script:
local Module = {}
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local TweenService = game:GetService("TweenService")
local Player = game:GetService("Players").LocalPlayer
local PlayerMouse: Mouse = Player:GetMouse()
local CommonData = ReplicatedStorage:WaitForChild("CommonData")
local Parts = CommonData:WaitForChild("Parts")
local PlacingEssentials = Parts:FindFirstChild("PlacingEssentials")
local Grid = workspace.Grid
local function CalculatePosition(X, Y, Z)
local GridUnit = 1
local function RoundToGrid()
return Vector3.new(math.floor(X / GridUnit + 0.5)*GridUnit, math.floor(Y / GridUnit + 0.5)*GridUnit, math.floor(Z / GridUnit + 0.5)*GridUnit)
end
return RoundToGrid()
end
function Module:PlacePart(Config)
local Part = Config.Part:Clone()
local SelectionBox = PlacingEssentials:FindFirstChild("SelectionBox"):Clone()
PlayerMouse.TargetFilter = Part
Part.Parent = workspace.Storage.Temp
SelectionBox.Parent = workspace.Storage.Temp
SelectionBox.Adornee = Part
--// By the way this part below (the position changing) is just an test prototype that i had made
Part.Position = CalculatePosition(PlayerMouse.Hit.X, PlayerMouse.Hit.Y, PlayerMouse.Hit.Z)
local c
c = RunService.RenderStepped:Connect(function()
TweenService:Create(Part, TweenInfo.new(0.1, Enum.EasingStyle.Quint), {Position = CalculatePosition(PlayerMouse.Hit.X, PlayerMouse.Hit.Y, PlayerMouse.Hit.Z)}):Play()
end)
end
return Module