Tweening model slingshots back for some reason

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.

Video of the issue:


(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 :confused:
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 :skull:

1 Like

This doesn’t really do anything.
Have you checked to see if the OnClientEvent fires twice?

Could it be this part of the code? It looks like its moving the model everytime the CFrameValue object is changed

CFrameValue:GetPropertyChangedSignal("Value"):Connect(function()
		model:SetPrimaryPartCFrame(CFrameValue.Value)
	end)
1 Like

I just checked and OnClientEvent only fires once

you should probably add a debounce to the touch event to make sure its not getting hit multiple times

Yep that was causing the problem lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.