I tried to tween the view model to achieve some kind of sway. So in this example code is basically what I did: Using a while loop to tween once every period of time. However, the tween did not run.
tool.Equipped:Connect(function()
while true do --swaySize is a local number value
ts:Create(viewModel.Head, TweenInfo.new(swaySize/10),{CFrame = camera.CFrame}):Play()
wait(swaySize/20)
end
end)
local ts = game:GetService("TweenService")
local tween = ts:Create(viewModel.Head, TweenInfo.new(swaySize/10), {CFrame = camera.CFrame})
tool.Equipped:Connect(function()
while true do --swaySize is a local number value
tween:Play()
wait(swaySize/20)
end
end)
It’s best to avoid recreating the same tween both in loops and in functions which are repetitively executed (in this case from a fired “Equipped” event).
This code your using right here might not exactly work because the cframe of the camera is constantly changing and if the tween is created out of the loop the target position would not be in the right place. Btw after I tried ur code there was no difference from the previous one ;-;
That’s a fair assessment to make, I wasn’t sure either which way, if that is the case then a simple change is all that is required.
local ts = game:GetService("TweenService")
local camera
local tween
tool.Equipped:Connect(function()
camera = workspace.CurrentCamera
tween = ts:Create(viewModel.Head, TweenInfo.new(swaySize/10), {CFrame = camera.CFrame})
while true do --swaySize is a local number value
tween:Play()
wait(swaySize/20)
end
end)
I’ve declared camera & tween as nonlocals in-case their assigned values are required elsewhere.
After I ran this thing it still had the same outcome as before. Its possible that I’ve tweened it the wrong way. Before I added the tween service the code was:
local camera = workspace.currentcamera
game:GetService("RenderStepped"):Connect(function()
viewModel.Head.CFrame = camera.CFrame
end)
You’re moving the head to the camera’s CFrame inside a RenderStepped & attempting to tween the head to the camera’s CFrame whenever the tool is activated (in a loop).
I thought its normal at first, but the thing really funny is that IT WORKED. So this tells me that the tween actually does play but some other things are causing it to not work.