Hi, i try to tween a value in my script but it gives me the error: “ContextActionService: Unexpected error while invoking callback: Unable to cast value to Object” here is my code
ammount = ammount + ammount
if canChange == true then
if ammount > 350 then
canChange = false
game:GetService("TweenService"):Create(ammount, TweenInfo.new(0.001), {ammount = 350}):Play()
wait(0.1)
canChange = true
end
game:GetService("TweenService"):Create(ammount, TweenInfo.new(ammount, Enum.EasingStyle.Linear), {ammount = 0}):Play()
end
pls dont reply if ur just gonna complain about the one line tweens thanks in advance
You can only tween instances iirc. The first parameter of Create should be an instance. In this case, since I assume you’re using an IntValue, it should be the the IntValue itself. Secondly, the third parameter of Create should be a property, in this case it would be ‘Value’.
You cant tween numeric values within a script, because they have no properties, and aren’t objects. What you can tween is values outside the script if thats what you mean when referring to numeric values.
In my experience a casting error is due to incompatible value types. Another thing to note is the extremely short duration of the first tween.
That tween is redundant, since tweens are only adjusted each frame (1/60th of a second) at the most. Remove that tween and just replace it with Amount = 350 (also dear god please remove the second “m” in “Ammount”, it’s driving me mad)
To actually fix your issue, we need to know the line in which the error is generated. I’m not confident the code you have provided is even relevant, given that it is Context Action Service we’re on about. Surrounding code is also required.
amountval = Instance.new("NumberValue",LocalPlayer)
function go(amount)
amountval.Value = amountval.Value + amount
end
game:GetService("RunService").Heartbeat:Connect(function()
if canChange == true then
if amountval.Value > 350 then
canChange = false
game:GetService("TweenService"):Create(amountval, TweenInfo.new(0.001), {Value = 350}):Play()
wait(0.1)
canChange = true
end
local tInfo = TweenInfo.new(10,Enum.EasingStyle.Linear)
local tween = game:GetService("TweenService"):Create(amountval,tInfo,{Value = 0})
tween:Play()
end
FRGO.AngularVelocity = -amountval.Value
FLGO.AngularVelocity = amountval.Value
RRGO.AngularVelocity = -amountval.Value
RLGO.AngularVelocity = amountval.Value
-- ^ these are the wheels that the number controls
end)