Making a tween always the same speed

I have a script that reads a NumberValue to set a textlabels position using a tween (I’m making a module to recreate the slot machine effect). Theres a math problem probably there, but i dont know how to solve it. I want the tween to dynamically change its time so it moves in the same speed even if the lenght is longer. The numbervalue goes from 0-9, so 10 different possibilities.

1 Like

bump cuz nobody replied (Sad) please help it would be SO useful

1 Like

I think it would help if you posted the script in question. :sunglasses:

1 Like
while wait() do
	local amt = script.Parent.amt.Value
	local curPos = script.Parent.TextLabel.Position.Y
	if amt == 0 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, 0, 0)
	elseif amt == 1 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -1, 0)
	elseif amt == 2 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -2, 0)
	elseif amt == 3 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -3, 0)
	elseif amt == 4 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -4, 0)
	elseif amt == 5 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -5, 0)
	elseif amt == 6 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -6, 0)
	elseif amt == 7 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -7, 0)
	elseif amt == 8 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -8, 0)
	elseif amt == 9 then
		pos = UDim2.new(script.Parent.TextLabel.Position.X.Scale, 0, -9, 0)
	end
	local taget = script.Parent.TextLabel
	local Info = TweenInfo.new(1--[[I want this number to change]], Enum.EasingStyle.Quad, Enum.EasingDirection.InOut)
	local c = game:GetService("TweenService"):Create(taget, Info, {Position = pos})
	c:Play()
	c.Completed:Wait()
end

It’s inefficient, i know. No need to make it more efficient for my usecase, could just do (-amt) but meh

2 Likes

First thing is you’ll have to find out how fast you want it to move. You can play around with the Speed variable until it’s about how you want it to be.

local Speed = 10 -- change to taste

local num = TextLabel.Size.X.Offset -- or whatever the size property is that you want to scale with

num = num / Speed

And then you’d set num as the Time property for the tween info. Again, you should play with it to get it exactly as you want, but that’s the general principal I followed trying to approach a similar problem before.

2 Likes

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