Hi! My script to make my screen shake after 5 seconds doesn’t work!
These are the locations of the script(s). I can’t figure out whats wrong with it?


local shakeEvent = game.ReplicatedStorage:WaitForChild("shakeScreen")
local Char = script.Parent
local Humanoid = Char:WaitForChild("Humanoid")
shakeEvent.OnClientEvent:Connect(function(Time)
local startTime = tick()
repeat
wait()
local endTime = tick()
local xOffset = math.random(-100,100) / 500
local yOffset = math.random(-100,100) / 500
local zOffset = math.random(-100,100) / 500
print("valid xyz offset")
Humanoid.CameraOffSet = Vector3.new(xOffset, yOffset, zOffset)
print("shaken")
until endTime - startTime >= time()
Humanoid.CameraOffset = Vector3.new(0,0,0)
print("re-stabailzed")
end)
Forummer
(Forummer)
3
Do you have a server script calling “:FireClient()” on the same RemoteEvent instance?
Yes I have it so it just waits 5 seconds then fires on all clients.
local shakeEvent = game.ReplicatedStorage:WaitForChild("shakeScreen")
wait(5)
shakeEvent:FireAllClients(5)
problem code:
shakeEvent.OnClientEvent:Connect(function(Time)
local startTime = tick()
repeat wait()
local endTime = tick()
until endTime - startTime >= time()
end)
endTime
is a local
inside your repeat block
you exit the block AT the until
word so at that point endTime
no longer exists
FIX:
shakeEvent.OnClientEvent:Connect(function(Time)
local endTime = tick() + Time
repeat wait()
--do things
until endTime <= time()
end)
I changed my script and this time there are no errors but it still doesnt work.
I made it now so there is a script inside of a proximity prompt and have fixed all my errors and changed the code entirely!
Thank you for the help though. I will mark this as a solution.