Hello i am trying to make a LocalScript to shake the players screen when I send a Request to a remote Event but this is whats happening: Video
Code:
local CameraShakeRemote = game.ReplicatedStorage.Remotes.ShakeScreen
local function shakeCamera(power, stime)
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
while not character:IsDescendantOf(game) do
character = player.Character or player.CharacterAdded:Wait()
end
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")
local camera = workspace.CurrentCamera
local intensity = power or 1
local duration = stime or 3
local startTime = 0
local shaking = false
local function update()
local elapsed = tick() - startTime
if shaking and elapsed < duration then
local offset = Vector3.new(
math.random() * intensity - intensity / 2,
math.random() * intensity - intensity / 2,
math.random() * intensity - intensity / 2
)
local originalOffset = humanoidRootPart.CFrame:pointToWorldSpace(Vector3.new(0, 0, -5))
camera.CFrame = CFrame.new(humanoidRootPart.Position + offset + originalOffset)
else
shaking = false
camera.CFrame = CFrame.new(humanoidRootPart.Position + humanoidRootPart.CFrame:vectorToWorldSpace(Vector3.new(0, 0, -5)))
end
end
local function onShake(power, stime)
startTime = tick()
shaking = true
update()
game:GetService("RunService").RenderStepped:Connect(update)
end
local function stopShake()
shaking = false
game:GetService("RunService").RenderStepped:Disconnect(update)
end
CameraShakeRemote.OnClientEvent:Connect(onShake)
CameraShakeRemote.OnClientEvent:Connect(stopShake)
end
shakeCamera()