Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make my tween function parse a float instead of a double?

Asked by 3 years ago

I have a basic tween function, but every time I run it it errors with: "Unable to cast double to TweenInfo". I know that I'm supposed to have a float there, but I need help turning the input into a float.

The function:

function tween1(object,t,property,value)
    local t = tonumber(t)
    local goal = {}
    goal[property] = value
    local tweenInfo = TweenInfo.new(t)
    local tween = tweenService:Create(object, t, goal)
    tween:Play()
end

How I call the function:

tween1(bar,0.25,"Size",UDim2.new(health / maxHealth, 0, 1, 0))

1 answer

Log in to vote
0
Answered by 3 years ago

I assume this is for a health bar? Gui's have their own tween services you can use much easier, and with 1 line

bar:TweenSize(UDim2.new(health/maxhealth,0,1,0),"Out","Quad",.25,true)

https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenSize https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenPosition https://developer.roblox.com/en-us/api-reference/function/GuiObject/TweenSizeAndPosition

Ad

Answer this question