I have a problem where the model inside my window doesn't move to the added amount in the brackets. I'm honestly not really sure how I can make it move 1.9/any amount studs up/side/down with the bricks inside the model. Is there a way in order to do that?
Layout of the model:
https://imgur.com/a/pdbzlYG
function Lock() if script.Parent.Locked.Value == false then script.Parent.Lock.Position = script.Parent.Lock.Position + Vector3.new(0,0.4,0) script.Parent.Locked.Value = true script.Parent.Lock.LockSound:Play() else script.Parent.Lock.Position = script.Parent.Lock.Position - Vector3.new(0,0.4,0) script.Parent.Locked.Value = false script.Parent.Lock.UnlockSound:Play() end end function FireFunction() if script.Parent.Open.Value == false then if script.Parent.Locked.Value == false then script.Parent.Glass.CFrame = script.Parent.Glass.CFrame - Vector3.new(0,1.9,0) script.Parent.Frame:MoveTo(Vector3.new(0,-1.9,0)) script.Parent.Glass.OpenClose:Play() script.Parent.Open.Value = true end else if script.Parent.Locked.Value == false then script.Parent.Glass.CFrame = script.Parent.Glass.CFrame + Vector3.new(0,1.9,0) script.Parent.Frame:MoveTo(Vector3.new(0,1.9,0)) script.Parent.Glass.OpenClose:Play() script.Parent.Open.Value = false end end end script.Parent.Lock.ClickToLock.MouseClick:Connect(Lock) script.Parent.Glass.Click.MouseClick:Connect(FireFunction)
I appreciate any help and am willing to learn, just let me know any fixes.
It's actually very simple, you were using MoveTo
which works
, however it's not recommended
to be used in your situation, instead you can set a primary part to your model, and use the method Model:SetPrimaryPartCFrame(CFrame)
.
Why? Because this method ignores collision, so it moves perfectly to where you want it to move.
The only thing you were doing wrong was setting the position to (0, + or -1.9, 0)
this is just going to move it to the y coordinate of negative or position 1.9 it won't move it up or down by 1.9 from where it is.
What you should do instead, is get the model's current Position, and add/subtract 1.9 to it.
For example:
script.Parent.Frame:MoveTo(Vector3.new(0,1.9,0)
Should be changed to:
local frame = script.Parent.Frame local origCFrame = frame:GetPrimaryPartCFrame() -- returns CFrame of primary part frame:SetPrimaryPartCFrame(origCFrame * CFrame.new(0, 1.9, 0))
This moves the model 'Frame'
up by 1.9 studs on the y-axis.
If you want to move it down, same thing just -1.9
NOTE: You have to set a primary part
to the model
that you are moving using this
method, if not, it won't work.
Mhhhm tried weldin the parts and only move one part so it always sticks to it