Need help with screen shake

I am trying to make a screen shake (Shakes along with the music) settings I had the screen shake work until I added the settings (That would allow you to change how much the screen Zooms out) but when I test The script doesn’t work. No errors. No screen shake.
Here is my script

wait(3)
while true do
local Max = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value
script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Text
wait(.25)
end

local RunService = game:GetService(“RunService”)

local Music = workspace:WaitForChild(“Sound”)
local CurrentCamera = workspace.CurrentCamera

local ScreenShakeSettings = {
CameraMinFOV = 70,
CameraMaxFOV = Max,
CameraMaxVolume = 1200
}

game:GetService(“RunService”).RenderStepped:connect(function()
local CurrentLoudness = Music.PlaybackLoudness
local Max = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value
local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
if FOV >= 75 then
CurrentCamera.FieldOfView = FOV
else
CurrentCamera.FieldOfView = 75
end
end)

(this is my first time using Dev Forum so I could not get any pictures up
)

1 Like

Would you mind putting your code in a more readable state using the Code block identifier (IDK what to call it)? You can do that by using tilde key, It looks like this:


You just type that 3 times, and everything between it and another set of three will be displayed as lua code.
Here’s an example:

local HelloWorld = "Hello World"
print(HelloWorld)

Ta da!

1 Like
wait(3)
while true do
local Max = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value
script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Text
wait(.25)
end

local RunService = game:GetService(“RunService”)

local Music = workspace:WaitForChild(“Sound”)
local CurrentCamera = workspace.CurrentCamera

local ScreenShakeSettings = {
CameraMinFOV = 70,
CameraMaxFOV = Max,
CameraMaxVolume = 1200
}

game:GetService(“RunService”).RenderStepped:connect(function()
local CurrentLoudness = Music.PlaybackLoudness
local Max = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value
local FOV = ScreenShakeSettings.CameraMinFOV + (ScreenShakeSettings.CameraMaxFOV - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)
if FOV >= 75 then
CurrentCamera.FieldOfView = FOV
else
CurrentCamera.FieldOfView = 75
end
end)

that’s his code

1 Like

Oh. I could’ve just done that myself. I don’t know why I didn’t think of that.

1 Like

Wrap your while true do loop in a coroutine so the rest of the code runs.

wait(3)

coroutine.wrap(function()
while true do
local Max = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value

script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Text
wait(.25)
end
end)()

local RunService = game:GetService("RunService")

local Music = workspace:WaitForChild("Sound")
local CurrentCamera = workspace.CurrentCamera

local ScreenShakeSettings = {
CameraMinFOV = 70,
CameraMaxVolume = 1200
}

RunService.RenderStepped:Connect(function()
local CurrentLoudness = Music.PlaybackLoudness

local Max = script.Parent.Parent.PlayerGui.OpenSettingGui.Frame.ScreenShake.ScreenShakeValue.Value.Value
local FOV = ScreenShakeSettings.CameraMinFOV + (Max - ScreenShakeSettings.CameraMinFOV) * (CurrentLoudness / ScreenShakeSettings.CameraMaxVolume)

if FOV >= 75 then
CurrentCamera.FieldOfView = FOV
else
CurrentCamera.FieldOfView = 75
end
end)

also your code does have some issues

ok that makes sense.Thank you for your help