I’m trying to Tween a model from one part to another, the model should stop when the Primary part touches the Stopping part, I expect the model to move smoothly but when it almost gets to the end it slingshots back and then finishes.
(If the video appears laggy just click on the streamables link)
I’m not fully sure how to fix this as I’ve never had this issue before
This is the local scripts code that moves the model once a remote event is fired:
(also the local script is inside of StarterPlayerScripts)
-- TS48
local replicatedStorage = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local remoteEvent = replicatedStorage:WaitForChild("MirrorMoveEvent")
local mirror = workspace:WaitForChild("Mirror")
local mirrorLoc = workspace:WaitForChild("MirrorLoc")
local mirrorStart = mirrorLoc:WaitForChild("MirrorStart") -- the location that the models primary part is at when the game starts
local mirrorFinal = mirrorLoc:WaitForChild("MirrorFinal") -- the location that the models primary part moves to
local mover = mirror:WaitForChild("Mover") -- the models primary part (note to self: check if I actually need this, atm it looks like I don't actually use this lol)
local touchConnection = nil
local info = TweenInfo.new(
2, -- Time it takes to move the model in seconds
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- The # of times the loop repeats (0 = does not repeat)
false, -- Reverses
.3 -- Delay Time before it starts to move in seconds
)
local function tweenModel(model, CF)
local CFrameValue = Instance.new("CFrameValue")
CFrameValue.Value = model:GetPrimaryPartCFrame()
CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
model:SetPrimaryPartCFrame(CFrameValue.Value)
end)
local tween = tweenService:Create(CFrameValue, info, {Value = CF})
tween:Play()
tween.Completed:Connect(function()
CFrameValue:Destroy()
end)
end
local function moveMirror()
tweenModel(mirror, mirrorFinal.CFrame)
touchConnection = mover.Touched:Connect(function(hit) -- Stops the function from being called again (at least I think thats how it works...)
if hit == mirrorFinal then
touchConnection:Disconnect()
touchConnection = nil
end
end)
end
remoteEvent.OnClientEvent:Connect(moveMirror)
Any help would be greatly appreciated as I’ve been stuck on this for awhile and don’t know what to do