Script Stops Working Out Of Nowhere

Okay, so first off i have 2 issues (I am unsure if i should make multiple posts or keep in a single one)

First Issue. I have a Script that makes the camera offset by a little when i am moving, this script was working 3 days ago, and i have not changed a single thing since and all of the sudden, the part where it would shake the screen simply doesn’t work now, it worked completely fine before and now randomly it doesn’t work at all
I don’t receive any errors either

here is an example

And here is the code

local runService = game:GetService("RunService")
local UIS = game:GetService("UserInputService")
local TS = game:GetService("TweenService")

local character = script.Parent
local humanoid = character:WaitForChild("Humanoid")

local Sprinting = false

local WalkBobbleXSpeed = 6.5
local WalkBobbleXMovingAmount = 0.25
local WalkBobbleYSpeed = 6.5
local WalkBobbleYMovingAmount = 0.25

local CurrentCamera = game.Workspace.CurrentCamera

local TweenWalk = TS:Create(CurrentCamera, TweenInfo.new(0.5), {FieldOfView = 70})
local TweenSprint = TS:Create(CurrentCamera, TweenInfo.new(0.5), {FieldOfView = 80})

local Anim = script:WaitForChild("Animation"):Clone()
Anim.Parent = character
local SprintAnim = humanoid:LoadAnimation(Anim)
SprintAnim:AdjustSpeed(0.6)

function UBE()
	local currentTime = tick()
	if humanoid.MoveDirection.Magnitude > 0 then
		local bobbleX = math.cos(currentTime * WalkBobbleXSpeed) * WalkBobbleXMovingAmount
		local bobbleY = math.abs(math.sin(currentTime * WalkBobbleYSpeed)) * WalkBobbleYMovingAmount

		local bobble = Vector3.new(bobbleX, bobbleY, 0)

		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, .25)
	else
		humanoid.CameraOffset = humanoid.CameraOffset * .75
	end
end

UIS.InputBegan:Connect(function(input, isTyping)
	if UIS:IsKeyDown(Enum.KeyCode.W) and UIS:IsKeyDown(Enum.KeyCode.LeftShift) then
		if Sprinting == false then
			if isTyping then return end
			Sprinting = true
			humanoid.WalkSpeed = 18
			SprintAnim:Play()
			TweenSprint:Play()
			WalkBobbleXSpeed = 9.5
			WalkBobbleXMovingAmount = 0.35
			WalkBobbleYSpeed = 9.5
			WalkBobbleYMovingAmount = 0.35
		end
	end
end)

UIS.InputEnded:Connect(function(input, isTyping)
	if input.KeyCode == Enum.KeyCode.W or input.KeyCode == Enum.KeyCode.LeftShift or input.KeyCode == Enum.KeyCode.Space then
		if Sprinting == true then
			if isTyping then return end
			Sprinting = false
			humanoid.WalkSpeed = 8
			SprintAnim:Stop()
			TweenWalk:Play()
			WalkBobbleXSpeed = 6.5
			WalkBobbleXMovingAmount = 0.25
			WalkBobbleYSpeed = 6.5
			WalkBobbleYMovingAmount = 0.25
		end
	end
end)


runService.RenderStepped:Connect(UBE)

Second issue. Is that when i am trying to edit RbxCharacterSounds to add a custom walk sound, i am returned with an error

" Failed to load sound 9180023886: Unable to download sound data"

I have tried to play the sound outside of the script, and it seems to work, but any id i put in the RbxCharacterSounds script i am returned with an error.

Here is the code for that

-- Roblox character sound script

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local AtomicBinding = require(script:WaitForChild("AtomicBinding"))

local SOUND_DATA : { [string]: {[string]: any}} = {
	Climbing = {
		SoundId = "rbxasset://sounds/action_footsteps_plastic.mp3",
		Looped = true,
	},
	Died = {
		SoundId = "rbxasset://sounds/uuhhh.mp3",
	},
	FreeFalling = {
		SoundId = "rbxasset://sounds/action_falling.mp3",
		Looped = true,
	},
	GettingUp = {
		SoundId = "rbxasset://sounds/action_get_up.mp3",
	},
	Jumping = {
		SoundId = "rbxasset://sounds/action_jump.mp3",
	},
	Landing = {
		SoundId = "rbxasset://sounds/action_jump_land.mp3",
	},
	Running = {
		SoundId = "rbxasset://9180023886",
		Looped = true,
		Pitch = 1,
	},
	Splash = {
		SoundId = "rbxasset://sounds/impact_water.mp3",
	},
	Swimming = {
		SoundId = "rbxasset://sounds/action_swim.mp3",
		Looped = true,
		Pitch = 1.6,
	},
}

-- map a value from one range to another
local function map(x: number, inMin: number, inMax: number, outMin: number, outMax: number): number
	return (x - inMin)*(outMax - outMin)/(inMax - inMin) + outMin
end

local function playSound(sound: Sound)
	sound.TimePosition = 0
	sound.Playing = true
end

local function shallowCopy(t)
	local out = {}
	for k, v in pairs(t) do
		out[k] = v
	end
	return out
end

local function initializeSoundSystem(instances)
	local player = instances.player
	local humanoid = instances.humanoid
	local rootPart = instances.rootPart
	
	local sounds: {[string]: Sound} = {}

	-- initialize sounds
	for name: string, props: {[string]: any} in pairs(SOUND_DATA) do
		local sound: Sound = Instance.new("Sound") 
		sound.Name = name

		-- set default values
		sound.Archivable = false
		sound.RollOffMinDistance = 5
		sound.RollOffMaxDistance = 150
		sound.Volume = 0.65

		for propName, propValue: any in pairs(props) do
			sound[propName] = propValue
		end

		sound.Parent = rootPart
		sounds[name] = sound
	end

	local playingLoopedSounds: {[Sound]: boolean?} = {}

	local function stopPlayingLoopedSounds(except: Sound?)
		for sound in pairs(shallowCopy(playingLoopedSounds)) do
			if sound ~= except then
				sound.Playing = false
				playingLoopedSounds[sound] = nil
			end
		end
	end

	-- state transition callbacks.
	local stateTransitions: {[Enum.HumanoidStateType]: () -> ()} = {
		[Enum.HumanoidStateType.FallingDown] = function()
			stopPlayingLoopedSounds()
		end,

		[Enum.HumanoidStateType.GettingUp] = function()
			stopPlayingLoopedSounds()
			playSound(sounds.GettingUp)
		end,

		[Enum.HumanoidStateType.Jumping] = function()
			stopPlayingLoopedSounds()
			playSound(sounds.Jumping)
		end,

		[Enum.HumanoidStateType.Swimming] = function()
			local verticalSpeed = math.abs(rootPart.AssemblyLinearVelocity.Y)
			if verticalSpeed > 0.1 then
				sounds.Splash.Volume = math.clamp(map(verticalSpeed, 100, 350, 0.28, 1), 0, 1)
				playSound(sounds.Splash)
			end
			stopPlayingLoopedSounds(sounds.Swimming)
			sounds.Swimming.Playing = true
			playingLoopedSounds[sounds.Swimming] = true
		end,

		[Enum.HumanoidStateType.Freefall] = function()
			sounds.FreeFalling.Volume = 0
			stopPlayingLoopedSounds(sounds.FreeFalling)
			playingLoopedSounds[sounds.FreeFalling] = true
		end,

		[Enum.HumanoidStateType.Landed] = function()
			stopPlayingLoopedSounds()
			local verticalSpeed = math.abs(rootPart.AssemblyLinearVelocity.Y)
			if verticalSpeed > 75 then
				sounds.Landing.Volume = math.clamp(map(verticalSpeed, 50, 100, 0, 1), 0, 1)
				playSound(sounds.Landing)
			end
		end,

		[Enum.HumanoidStateType.Running] = function()
			stopPlayingLoopedSounds(sounds.Running)
			sounds.Running.Playing = true
			playingLoopedSounds[sounds.Running] = true
		end,

		[Enum.HumanoidStateType.Climbing] = function()
			local sound = sounds.Climbing
			if math.abs(rootPart.AssemblyLinearVelocity.Y) > 0.1 then
				sound.Playing = true
				stopPlayingLoopedSounds(sound)
			else
				stopPlayingLoopedSounds()
			end
			playingLoopedSounds[sound] = true
		end,

		[Enum.HumanoidStateType.Seated] = function()
			stopPlayingLoopedSounds()
		end,

		[Enum.HumanoidStateType.Dead] = function()
			stopPlayingLoopedSounds()
			playSound(sounds.Died)
		end,
	}

	-- updaters for looped sounds
	local loopedSoundUpdaters: {[Sound]: (number, Sound, Vector3) -> ()} = {
		[sounds.Climbing] = function(dt: number, sound: Sound, vel: Vector3)
			sound.Playing = vel.Magnitude > 0.1
		end,

		[sounds.FreeFalling] = function(dt: number, sound: Sound, vel: Vector3): ()
			if vel.Magnitude > 75 then
				sound.Volume = math.clamp(sound.Volume + 0.9*dt, 0, 1)
			else
				sound.Volume = 0
			end
		end,

		[sounds.Running] = function(dt: number, sound: Sound, vel: Vector3)
			sound.Playing = vel.Magnitude > 0.5 and humanoid.MoveDirection.Magnitude > 0.5
		end,
	}

	-- state substitutions to avoid duplicating entries in the state table
	local stateRemap: {[Enum.HumanoidStateType]: Enum.HumanoidStateType} = {
		[Enum.HumanoidStateType.RunningNoPhysics] = Enum.HumanoidStateType.Running,
	}

	local activeState: Enum.HumanoidStateType = stateRemap[humanoid:GetState()] or humanoid:GetState()

	local stateChangedConn = humanoid.StateChanged:Connect(function(_, state)
		state = stateRemap[state] or state

		if state ~= activeState then
			local transitionFunc: () -> () = stateTransitions[state]

			if transitionFunc then
				transitionFunc()
			end

			activeState = state
		end
	end)

	local steppedConn = RunService.Stepped:Connect(function(_, worldDt: number)
		-- update looped sounds on stepped
		for sound in pairs(playingLoopedSounds) do
			local updater: (number, Sound, Vector3) -> () = loopedSoundUpdaters[sound]

			if updater then
				updater(worldDt, sound, rootPart.AssemblyLinearVelocity)
			end
		end
	end)

	local function terminate()
		stateChangedConn:Disconnect()
		steppedConn:Disconnect()
	end
	
	return terminate
end

local binding = AtomicBinding.new({
	humanoid = "Humanoid",
	rootPart = "HumanoidRootPart",
}, initializeSoundSystem)

local playerConnections = {}

local function characterAdded(character)
	binding:bindRoot(character)
end

local function characterRemoving(character)
	binding:unbindRoot(character)
end

local function playerAdded(player: Player)
	local connections = playerConnections[player]
	if not connections then
		connections = {}
		playerConnections[player] = connections
	end

	if player.Character then
		characterAdded(player.Character)
	end
	table.insert(connections, player.CharacterAdded:Connect(characterAdded))
	table.insert(connections, player.CharacterRemoving:Connect(characterRemoving))
end

local function playerRemoving(player: Player)
	local connections = playerConnections[player]
	if connections then
		for _, conn in ipairs(connections) do
			conn:Disconnect()
		end
		playerConnections[player] = nil
	end
	
	if player.Character then
		characterRemoving(player.Character)
	end
end

for _, player in ipairs(Players:GetPlayers()) do
	task.spawn(playerAdded, player)
end
Players.PlayerAdded:Connect(playerAdded)
Players.PlayerRemoving:Connect(playerRemoving)

I am totally stumped and i appreciate anyones help.

1 Like

The sound issue is most likely happening because you don’t own the sound. Not sure if you know, but there was an audio update that came out not too long ago that made all audios over 7 seconds long private (worse update ever). Sound could also not be approved yet.

As for the camera shake, maybe try changing the values as I tried testing the same function and the print result was barely over 0.
image

1 Like

I am the one who made the sound, and when i change the values of the camera shake, it still doesn’t work i made sure by making the camera shake by 3 and even 6 studs to test it, to see if the issue was because the values were too low.

I tried changing the lerp amount from .25 to 1, and it did create some minor movement.

Could be that the audio is broken, try reuploading it and see what happens.

1 Like

the audio issue i don’t believe its because of the sound being broken, because when i use other sound id’s that i have made i am still returned with that error


I changed the values to be alot higher


But still nothing shakes the camera

Weird, try printing the bobble variable and the new lerp value.

1 Like

Not quite sure what you meant, but here are the Y and X values

Here are the changes I made if it helps.

1 Like

Could you put the code in a lua box, if you dont mind if not i can just type it out

Yep

local WalkBobbleXSpeed = 6.5
local WalkBobbleXMovingAmount = 1
local WalkBobbleYSpeed = 6.5
local WalkBobbleYMovingAmount = 1

function UBE()
	local currentTime = tick()
	if humanoid.MoveDirection.Magnitude > 0 then
		local bobbleX = math.cos(currentTime * WalkBobbleXSpeed) * WalkBobbleXMovingAmount
		local bobbleY = math.abs(math.sin(currentTime * WalkBobbleYSpeed)) * WalkBobbleYMovingAmount

		local bobble = Vector3.new(bobbleX, bobbleY, 0)
		print(bobble)
		humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 1)
	else

		humanoid.CameraOffset = humanoid.CameraOffset * .75
	end
end
1 Like

This still didn’t make the camera shake. the reason i am confused is because the code was working not even 2 days ago, and i havent made any changes and it is broken now, i have even tried going into a actual game to see if it is a roblox studio problem

Just realized that the User Input functions are overriding the original values, if you commented those out I’m pretty sure you’d be able to see some movement.

The userinputservice functions arent overriding the original values but i double checked to make sure, and it still didn’t work unfortunately

Are you sure you used these values and you completely commented out both Input functions?

local WalkBobbleXSpeed = 6.5
local WalkBobbleXMovingAmount = 1
local WalkBobbleYSpeed = 6.5
local WalkBobbleYMovingAmount = 1
humanoid.CameraOffset = humanoid.CameraOffset:lerp(bobble, 1) --.25 to 1

Yes i did exactly that and i still did not get any movement at all

Yea that’s weird, here’s how mine turned out.

well now this makes me even more confused, can you try my original script to see if it works, maybe something is disabling the script or something is interfering with mine

Copied and pasted the original code you had (with the values I changed), and it worked. Though I did comment out the part where it waited and loaded the sprint animation.

1 Like

okay thank you, this atleast lets me know that its a issue with my roblox studio, and not the script

1 Like

I have figured out the issue, i had another script that was changing the offset of the camera. thank you so much, i really appreciate the help

1 Like