"Unable to cast value to Object" when making a dictionary

This function is supposed to make and return a tween that varies the value of a specific IntValue (defined as AMOUNT)

function makeTween(t,x)
	return game:GetService("TweenService"):Create(
		AMOUNT.Value,
		TweenInfo.new(t),
		{Value = x} --Error
	)
end

For some reason, I’m getting a casting error, when I shouldn’t be casting an int to an object.

Full Script
-- "Constants"
local JUMPTIME = .5
local AMOUNT = script.Parent:FindFirstChild("Amount")
local TEXTOBJ = script.Parent.Number
local FLASHTIME = .5

-- "Variables"
local event = game.ReplicatedStorage:WaitForChild("CrateTouched")
local Gui = require(game.ReplicatedStorage:WaitForChild("GuiToggler"))(script.Parent)

local colors = {
	Color3.fromRGB(0,170,0),
	Color3.fromRGB(0,255,0)
}

function makeTween(t,x)
	return game:GetService("TweenService"):Create(
		AMOUNT.Value,
		TweenInfo.new(t),
		{Value = x}
	)
end

AMOUNT.Changed:Connect(function(x)
	TEXTOBJ.Text = "$"..tostring(x)
end)

event.OnClientEvent:Connect(function(amt, t)
	Gui:open()
	
	local jumpamt = t/JUMPTIME -- How many times we're jumping
	
	for i = 1,jumpamt do --Do this for however many times we can cram in there with our jumptime
		local x = i == jumpamt and amt or math.random(5,5000) --If this is the last jump, then show the real winnings
		print(x)
		local t = makeTween(JUMPTIME, x)
		t:Play()
		t.Completed:Wait()
	end
	
	for i = 1,3 do
		TEXTOBJ.TextColor3 = colors[2]
		wait(FLASHTIME/2)
		TEXTOBJ.TextColor3 = colors[1]
		wait(FLASHTIME/2)
	end
	
	Gui:close()
end)

The first argument of TweenService:Create() must be the object that you are tweening the property of. AMOUNT.Value is not an object, it is an Integer. You should only have AMOUNT for the first argument and leave the third argument for the tweening of the properties.

function makeTween(t,x)
	return game:GetService("TweenService"):Create(
		AMOUNT,
		TweenInfo.new(t),
		{Value = x}
	)
end

This should fix your problem, let me know if you are still having issues.

2 Likes