I’ve tried to use OverlapParams. but its very confusing.
heres my code:
local Tool = script.Parent
local RunService = game: GetService("RunService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Player = game: GetService("Players").LocalPlayer
local Mouse = Player:GetMouse()
local Template = ReplicatedStorage.Parts.Part
local Overlap = OverlapParams.new()
Overlap.FilterType = Enum.RaycastFilterType.Exclude
local function SnapTo(X : number, Increment : number)
return math.floor(X / Increment) * Increment
end
local function VectorSnapped(Vector : Vector3, Increment : number)
return Vector3.new(
SnapTo(Vector.X, Increment),
SnapTo(Vector.Y, Increment),
SnapTo(Vector.Z, Increment)
)
end
local function Equipped()
print("work")
local Cloned = Template:Clone()
Cloned.Parent = game.Workspace
Mouse.TargetFilter = Cloned
local run = game["Run Service"].Heartbeat:Connect(function()
local check = VectorSnapped(Vector3.new(Mouse.Hit.X,Mouse.Hit.Y,Mouse.Hit.Z), 1)
Cloned.Position = check
end)
Tool.Unequipped:Connect(function()
run:Disconnect()
Cloned:Destroy()
return
end)
end
Tool.Equipped:Connect(function()
Equipped()
end)
That’s because the mouse is on the floor and since a part’s origin is the center, the center will also be on the floor. To avoid this just add or subtract half the part’s size on the final position by using the face the mouse is currently on.
if mouse.TargetSurface == Enum.NormalId.Top then
yourpos += Vector3.new(0, part.Size.Y/2, 0)
elseif mouse.TargetSurface == Enum.NormalId.Left then
--...
end
This will correctly offset the part.
If the part isn’t a rectangle or cube (eg: some mesh or complex model) just act like it is.