I am trying to make a screenshake for my game however whenever I tween the humanoids cameraoffset it errors with Unable to cast value to Object. However this does work on its own when I do CameraOffset = vector3 but I dont want it to be instant. I was wondering if there is something that I am unaware of or if there is an issue else where in my code.
local function RanVector()
return Vector3.new(Random.new():NextNumber(-Amount, Amount),0,Random.new():NextNumber(-Amount, Amount))
end
local vector = RanVector()
local tween = game:GetService("TweenService"):Create(CameraClient, TweenInfo.new(0.5), {CameraOffset = vector})
tween:Play()
Shouldnt the first argument in the tween create function be the humanoid? local tween = game:GetService("TweenService"):Create(Humanoid, TweenInfo.new(0.5), {CameraOffset = vector})
Also if youre going to play a tween right after creating it, you can just do this instead:
Well, from what i understand about tweens, the Unable to cast value to Object error means that the property does not exist, or cannot be tweened for whatever reason, or you named it incorrectly in the table.
Looks like you should be using a lerping function instead.
local function TweenVector(StartVector, EndVector, Duration)
local Time = 0
repeat
Time += task.wait()
local Vector = StartVector:Lerp(EndVector, Time / Duration)
print(Vector)
until Time > Duration
end
TweenVector(Vector3.new(0, 0, 0), Vector3.new(1, 1, 1), 1)