I recently made a successful script for a chest which flips open if you click on it. However, it rotates weirdly upon clicking. More like rotating around another point, instead of the object's center. Here is the script:
function onClicked(PlayerWhoClicked) script.Parent.Lid.CFrame = CFrame.Angles(math.rad(5), 0,0) end script.Parent.ClickDetector.MouseClick:connect(onClicked)
Is there any specific type of rotation I should use?
Well we can use CFrame to do this
If our object is a model use :SetPrimaryPartCFrame() if a basepart then change its CFrame It will also check if the model has a primarypart so make sure it's set
local thing = workspace.Model if thing:IsA("BasePart") then thing.CFrame = thing.CFrame*CFrame.Angles(math.rad(5), 0,0) elseif thing:IsA("Model") and thing.PrimaryPart~=nil then thing:SetPrimaryPartCFrame(thing:GetPrimaryPartCFrame()*CFrame.Angles(math.rad(5), 0,0)) end
Now let's combine your script and this one I will also combine your function and where u call it
script.Parent.ClickDetector.MouseClick:connect(function(plr) local thing = script.Parent.Lid if thing:IsA("BasePart") then thing.CFrame = thing.CFrame*CFrame.Angles(math.rad(5), 0,0) elseif thing:IsA("Model") and thing.PrimaryPart~=nil then thing:SetPrimaryPartCFrame(thing:GetPrimaryPartCFrame()*CFrame.Angles(math.rad(5), 0,0)) end end)