I’m having problems where when I go to move a model, it’s rotation keeps changing. Here’s the code relevant to the question. This code is inside a BillboardGuil, which gets parented to the playergui and required when I click on a model. If I click off the model, or click a new model, it gets deleted (and a new one is created and required if I clicked on a new model)
return function(gridLock)
local IsMoving = false
local _, Rotation, _ = Model.PrimaryPart.CFrame:ToEulerAnglesXYZ()
local OriginalPosition = Model.PrimaryPart.CFrame
local Rotation = math.deg(Rotation)
Move.MouseButton1Down:Connect(function()
IsMoving = true
UserInputService.MouseIconEnabled = false
Rotate.Visible = false
end)
Mouse.Move:Connect(function()
if not IsMoving then return end
-- Check for seats
for _, v in pairs(Model:GetDescendants()) do
if v:IsA('Seat') then
local Occupant = v.Occupant
if Occupant then
-- Make the player sitting down stand up
Occupant.Sit = false
end
end
end
-- Do checks to make sure it's being placed within their base
local CheckForFloor = Ray.new(Character.HumanoidRootPart.Position, Vector3.new(0, -50, 0))
local Floor, FloorPos = workspace:FindPartOnRayWithWhitelist(CheckForFloor, {workspace.Plots.Interiors[Player.Name].Build.InteriorElements})
-- Not players floor/returned nil for some reason
if not Floor then return end
-- Set models parts to not collideable
for i, v in pairs(Model:GetDescendants()) do
if v:IsA('BasePart') or v:IsA('UnionOperation') or v:IsA('MeshPart') then
v.CanCollide = false
end
end
local UnitRay = Camera:ScreenPointToRay(Mouse.X, Mouse.Y, 1)
local NewRay = Ray.new(UnitRay.Origin, UnitRay.Direction * 1000)
local Hit, Pos, Normal = workspace:FindPartOnRayWithIgnoreList(NewRay, {Model, Player.Character, workspace.Plots.Interiors[Player.Name].Build.Door})
if not Hit then return end
local PosX, PosY, PosZ
if not gridLock then
-- Has grid lock off
if false then -- Ignore this, checks for gamepass in game (default false)
-- Owns the pass, do not lock to grid
PosX = Pos.X
PosY = Pos.Y
PosZ = Pos.Z
end
end
if not PosX and not PosY and not PosZ then
-- Does not own gamepass or has advanced placement off
PosX = math.floor((Pos.X / 0.5) + 0.5) * 0.5
PosY = math.floor((Pos.Y / 0.5) + 0.5) * 0.5
PosZ = math.floor((Pos.Z / 0.5) + 0.5) * 0.5
end
local NewPos = Vector3.new(PosX, PosY, PosZ)
Model:SetPrimaryPartCFrame(
CFrame.new(NewPos, NewPos + Normal * 15) *
CFrame.Angles(-math.rad(90), math.rad(Rotation), 0) *
CFrame.new(0, (Model.PrimaryPart.Size.Y / 2) - 0.25, 0)
)
end)
end
Note:
Blue button = move
Black button = rotate
Another video showing me rotating the model. It’s like when I move it, it has to reset back to a default position.