I’m trying to make a system where if you click on a model it picks it up and you can move it, however atm when I click on the model it automatically just rotates 180 degrees for no reason.
Ok, I read your other post (I assume you’re talking about this), but it’s hard to follow it and know what you currently have. Could you post the function/code you’re currently using (and maybe post it there so as to hopefully resolve that post)
mouse.Button1Down:connect(function()
if movement then
local hit = mouse.Target
if hit and hit.Parent.Parent == base.ItemHolder then
if hit.Parent:FindFirstChild('Sign') == nil then
initiatePlacement(hit.Parent, hit.Parent.PrimaryPart.Orientation, false)
clientDestroyed:FireServer(hit.Parent, false)
end
end
end
end)
function initiatePlacement(itemName, orientation, placing)
cancelPlacement()
if orientation then
dummyModel = items[itemName.Name]:Clone()
print(orientation)
dummyModel:SetPrimaryPartCFrame(itemName:GetPrimaryPartCFrame():inverse())
currentItemName = itemName.Name
else
dummyModel = items[itemName]:Clone()
currentItemName = itemName
end
for _, object in pairs(dummyModel:GetChildren()) do
if object:IsA('BasePart') then
object.CanCollide = false
end
end
end
For some reason if I do :inverse() after the GetPrimaryPartCFrame() it doesn’t rotate the model 180 degrees if the models orientation is [0, -90, 0] or [0, 90, 0] but when the models orientation is [0, -180, 0] it sets it to [0, 0, 0] for no reason and vice versa. If I remove the inverse() however then it flips the model 180 degrees no matter what it’s orientation is. So I don’t know why it keeps flipping the model if it’s [0, -180, 0] or [0, 0, 0]
1: What does cancelPlacement() do? Would it happen to change the CFrame of itemName?
2: Are dummyModel and itemName cloned from the same source (items[itemName.Name])? Assuming they are then you should have no problems with setting the PrimaryPart CFrame to itemName’s PrimaryPart CFrame.
This seems to me like you might have some obscure line of code. I’d recommend going through you’re entire script and commenting out all CFrames applied to itemName and dummyModel. Then you can slowly re-add them in until the problem line presents itself.
function cancelPlacement()
destroying = false
if currentItemName then
plane:disable()
pathPlane:disable()
if dummyModel.Parent then
dummyModel:Destroy()
end
dummyModel = nil
signal = nil
currentItemName = nil
end
end
EDIT and the only CFrames in the entire script are the Set and Get primary part Cframes
Would it be possible to get a place file? Or if not, play the game and chat with you? Also, have you looked into the Dragger service? It pretty much makes clicking a dragging as simple as sending client signals to the server, and passing them over to the dragger service there.
local desiredPosition = Vector3.new(whatever)
local delta = desiredPosition - model.PrimaryPart.Cframe.p
model:SetPrimaryPartCframe(model.PrimaryPart.CFrame+delta)
Then if you want to rotate 90 degrees
Function Rotate()
local pp=model.PrimaryPart
local CF =(pp.Cframe-pp.Position)*CFrame.Angles(0,math.pi/2,0) + pp.Position
model:SetPrimaryPartCFrame(CF)
end
This will just rotate it in the Y axis every time it is called, no need to track rotation at all.