Tween Loop Jittery

So I’ve been messing around with tween loops and the likes and I have come across an issue where the tween is crazy jittery, now part of me thinks this is the loop that is part of the issue but I want some insight on what some others think about it and what could possibly be better for this.

runService.Heartbeat:Connect(function()
	if buttonDown and values.barrel.Value == true and values.ammunition.Value >= 0 and values.reloading.Value == false then
		if uis.KeyboardEnabled then
			local mousePos = mouse.Hit.Position
			remoteEvents.fired:FireServer(mousePos, buttonDown)
			if values.capturable.Value == false then
				values.ammunition.Value = values.ammunition.Value - 1
			end
		end
		local serverStream = game.Workspace.StreamData:WaitForChild(player.Name)
		if serverStream then
			if streamEffect == nil then
				serverStream.Transparency = 1
				for i,v in pairs(serverStream.Electricity:GetChildren()) do
					v.Enabled = false
				end
				streamEffect = game.ReplicatedStorage.Equipment.FX.Stream:Clone()
				streamEffect.Parent = game.Workspace.StreamData
				streamEffect.Name = "clientStream"
			else
				local math1 = values.tweenPositions.mathValue1.Value
				local math2 = values.tweenPositions.mathValue2.Value
				streamEffect.CFrame = CFrame.lookAt((game.Workspace.StreamData:WaitForChild("Part").Position + tool.Handle.Tip.Position)/2, game.Workspace.StreamData:WaitForChild("Part").Position, Vector3.yAxis) * CFrame.Angles(0, math.rad(90),0)
				streamEffect.Startpoint.WorldPosition = tool.Handle.Tip.Position
				streamEffect.Endpoint.WorldPosition = game.Workspace.StreamData:WaitForChild("Part").Position
				local properties1 = {
					["WorldPosition"] = ((streamEffect.Startpoint.WorldPosition + streamEffect.Segment2.WorldPosition) / 2) + Vector3.new(math.random(math1, math2), math.random(math1, math2), math.random(math1, math2))
				}
				local properties2 = {
					["WorldPosition"] = ((streamEffect.Segment1.WorldPosition + streamEffect.Segment3.WorldPosition) / 2) + Vector3.new(math.random(math1, math2), math.random(math1, math2), math.random(math1, math2)) 
				}
				local properties3  = {
					["WorldPosition"] = ((streamEffect.Segment2.WorldPosition + streamEffect.Endpoint.WorldPosition) / 2) + Vector3.new(math.random(math1, math2), math.random(math1, math2), math.random(math1, math2)) 
				}
				local tween1 = tweenService:Create(game.Workspace.StreamData:WaitForChild("clientStream").Segment1, tweenInfo, properties1)
				local tween2 = tweenService:Create(game.Workspace.StreamData:WaitForChild("clientStream").Segment2, tweenInfo, properties2)
				local tween3 = tweenService:Create(game.Workspace.StreamData:WaitForChild("clientStream").Segment3, tweenInfo, properties3)
				tween1:Play()
				tween2:Play()
				tween3:Play()
			end
		end
	end
end)

Specifically bottom after the else is where the tween stuff happens and here is what my tweenInfo looks like followed by a video of what is going on:

local tweenInfo = TweenInfo.new(
	0.4,
	Enum.EasingStyle.Sine,
	Enum.EasingDirection.Out,
	0,
	true,
	0
)

Any help to point me in the right direction will be greatly appreciated. Thank you to whoever responds in advance!

2 Likes

The reason might be that your running the tween in Run Service, maybe try putting it somewhere and see if it does anything.

1 Like

Already tried that with a constantly updating position, doesn’t work because the tween has to change so the bones in the stream know where to go and the likes.

Tweens run asynchronously, meaning that they can run over the top of each other. Your code is playing the same tween every heartbeat, which is much faster than .4s that your Tween takes to complete.

You need a form of debounce to prevent the tweens being called on top of one another and it can be as simple as declaring a boolean variable outside the Heartbeat event function and disabling it before the tween starts, and then re-enabling it just after it finishes.

1 Like

This worked! Thank you so much!

1 Like

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