Why script is not working?

  1. What do you want to achieve? Fix my script

  2. What is the issue? I don’t know why my script isn’t working.

  3. What solutions have you tried so far? I tried to look at DevForum but i din’t found an solution.

Script:

local ShakeEvent = game.ReplicatedStorage.Events:WaitForChild("HyperScreenShake")
local Character = script.Parent
local Humanoid = Character:WaitForChild("Humanoid")
ShakeEvent.OnClientEvent:Connect(function(Time)
	local StartTime = tick()
	repeat
		wait()
		local EndTime = tick()
		local xOffset = math.random(-505,505)/500	
		local yOffset = math.random(-505,505)/500
		local zOffset = math.random(-505,505)/500
		Humanoid.CameraOffset = Vector3.new(xOffset, yOffset, zOffset)
	until EndTime - StartTime >= Time
	Humanoid.CameraOffset = Vector3.new(0, 0, 0)
end)

Why this ins’t working?

it’s not working because Humanoid.CameraOffset is read only

Its Giving me this error: Attempt to compare nil <= number

I think Time Variable in

until EndTime - StartTime >= Time

equal nil sure print it in client or when fire client

sadly it doesn’t print nothing

thats why cuz you cant equal or greater number with nil value show me server or script thats have fire client
there some tips can use it to avoid this error make sure write this

tonumber(Time)

try print type of this value and make sure its number

print(type(Time)) ---Output should get number

Show the code where you’re firing the remote event.

script.Parent.Touched:Connect(function()
game.ReplicatedStorage.Events.HyperScreenShake:FireAllClients()

end)

thats why you should variable put time like this

script.Parent.Touched:Connect(function()
     game.ReplicatedStorage.Events.HyperScreenShake:FireAllClients(4)-- sec you can change it

end)

thats why Time Variable =nil you should put value for it

You aren’t passing any parameter, but are trying to access “Time” in the event.
ShakeEvent.OnClientEvent:Connect(function(Time)

To add onto this, you should be using os.clock() instead of tick() because it has way more precision down to the nanoseconds. Next, you should be using task.wait() instead of wait() since it’s a lot more reliable and actually works with the task scheduler (and can have lower delays than wait). Now this one is optional but makes things look a little cleaner, but it’s generally better to use Vector3.zero if your gonna be making a zero vector. (much faster to access a property than to construct a whole new object)

1 Like