Why is my camera bopping script not working?

Im trying to make it so that when the character runs, the humanoid.CameraOffset will start going up and down but, its not working nor am I getting any errors.

Script

--\\Variables//--

local TS = game:GetService("TweenService")

local Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")

local info = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)

local Tween1 = TS:Create(Humanoid, info, {CameraOffset = Vector3.new(0,1,0)})

local Tween2 = TS:Create(Humanoid, info, {CameraOffset = Vector3.new(0,-1,0)})

--\\------//--

while Humanoid.Running == true do
	task.wait(1.5)
	Tween1:Play()
	
	if Tween1.Completed then
		Tween2:Play()
	end
end
--\\Variables//--

local TS = game:GetService("TweenService")

local Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")

local info = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)

local Tween1 = TS:Create(Humanoid, info, {CameraOffset = Vector3.new(0,1,0)})

local Tween2 = TS:Create(Humanoid, info, {CameraOffset = Vector3.new(0,-1,0)})

--\\------//--

while Humanoid.Running == true do
	task.wait(1.5)
	Tween1:Play()
	
	Tween1.Completed:Wait()
	Tween2:Play()
end

Try this.

Before I do, can you elaborate on any changes made and or what was wrong with my script?

You used an IF statement, which meant that it only checked once, then never checked again, and of course, Tween1 wouldn’t have been finished yet and Tween2 would never play.

In my script, Tween2 waited until Tween1 completed instead of only checking once.

2 Likes

Thanks for the recommendation but, its still not working.

I’m not sure if running can be detected (true / false) but you can use the function done on it.
It would look like this:

--\\Variables//--

local TS = game:GetService("TweenService")
local Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
local info = TweenInfo.new(0.75, Enum.EasingStyle.Linear, Enum.EasingDirection.In, 0, false, 0)
local Tween1 = TS:Create(Humanoid, info, {CameraOffset = Vector3.new(0,1,0)})
local Tween2 = TS:Create(Humanoid, info, {CameraOffset = Vector3.new(0,-1,0)})
local plrRunning = false

--\\------//--

Humanoid.Running:Connect(function(speed)
	if speed > 0 then -- player running
		if plrRunning == false then --check if tween already running
			plrRunning = true
			repeat --repeat until player stop running
				Tween1:Play()
				Tween1.Completed:Wait()
				Tween2:Play()
				Tween2.Completed:Wait()
			until plrRunning == false
		end
	else --detect if player stop running
		plrRunning = false
	end
end)
1 Like

Does this need to be in StarterPlayerScripts?

No in StarterCharacterScripts.

1 Like