Hello! I’m making a game (not like pls donate), and i was wondering how i could recreate this CAMERA shake effect:
-- LocalScript: ScreenShakeScript
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local ShakeintensityX = Instance.new("NumberValue")
local ShakeintensityY = Instance.new("NumberValue")
ShakeintensityX.Value = 50
ShakeintensityY.Value = 50
-- Function to shake the camera
local function ScreenShaker()
local cam = workspace.CurrentCamera
local shakeDuration = 2
local shakeSpeed = 1
-- Tween to gradually reduce the intensity over time
local tweenInfo = TweenInfo.new(shakeDuration, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut)
local tweenX = TweenService:Create(ShakeintensityX, tweenInfo, {Value = 0})
local tweenY = TweenService:Create(ShakeintensityY, tweenInfo, {Value = 0})
tweenX:Play()
tweenY:Play()
local ShakeEffect
local startTime = tick()
ShakeEffect = RunService.RenderStepped:Connect(function()
local elapsedTime = tick() - startTime
local intensityFactor = math.max(1 - (elapsedTime / shakeDuration), 0)
local Xintensity = ShakeintensityX.Value * intensityFactor
local Yintensity = ShakeintensityY.Value * intensityFactor
local x, y
if Xintensity > 0 then
x = math.random(-Xintensity, Xintensity) / 100
else
x = 0
end
if Yintensity > 0 then
y = math.random(-Yintensity, Yintensity) / 100
else
y = 0
end
-- Apply the shake to the camera's CFrame
cam.CFrame = cam.CFrame * CFrame.new(x, y, 0)
end)
wait(shakeDuration)
ShakeEffect:Disconnect()
end
game.ReplicatedStorage.Remotes:WaitForChild("CameraShakeEvent").OnClientEvent:Connect(function()
ScreenShaker()
end)
I have this script currently, it doesnt exactly work how i wanted it to but i guess it shakes still