Local script doesn't update with the value

Code
math.randomseed(tick())
local runService = game:GetService("RunService")

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local shaking = script:WaitForChild("Value").Value

local nextFire = 1

--
local shakeRate = 0 
local shakeMin = 0  
local shakeMax = shaking
	
runService.RenderStepped:Connect(function()
	if elapsedTime() > nextFire then
		nextFire = elapsedTime() + shakeRate
		hum.CameraOffset = Vector3.new(math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000)
	end
end)

As you can see in the code, I connected the variable called “shakeMax” with the child of script, a number value.
This script shakes the camera all the time if shakeMax is bigger than 0.
I changed the value to 0 and tested it, camera doesn’t shake. Code works :+1:
then
I changed the value to 200 and tested it, camera shakes. Code works again :+1:
BUT
When the value is 0 and I change the value to 200, camera doesn’t shake :-1:
So the problem is, code doesn’t update with the value.
Please help
image

The reason it does not update is because no where in your code have you told it to update your value when it is changed.

Try this:

math.randomseed(tick())
local runService = game:GetService("RunService")

local char = script.Parent
local hum = char:WaitForChild("Humanoid")
local shaking = script:WaitForChild("Value")

local nextFire = 1

--
local shakeRate = 0 
local shakeMin = 0  
local shakeMax = shaking.Value

shaking:GetPropertyChangedSignal("Value"):Connect(function()
    shakeMax = shaking.Value
end)

runService.RenderStepped:Connect(function()
	if elapsedTime() > nextFire then
		nextFire = elapsedTime() + shakeRate
		hum.CameraOffset = Vector3.new(math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000)
	end
end)

This could work as well:

math.randomseed(tick())
local runService = game:GetService("RunService")

local char = script.Parent
local hum = char:WaitForChild("Humanoid")

local nextFire = 1

--
local shakeRate = 0 
local shakeMin = 0  
local shakeMax = 0

runService.RenderStepped:Connect(function()
    local shaking = script:WaitForChild("Value").Value
    shakeMax = shaking
	if elapsedTime() > nextFire then
		nextFire = elapsedTime() + shakeRate
		hum.CameraOffset = Vector3.new(math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000, math.random(shakeMin, shakeMax)/1000)
	end
end)
1 Like