Shaking script with button

I have a question about a script. I am try revamping my map ( Terminated Factory )
I want a script. When i press a button, it will start shaking now.
I need :
A script that working
Where i have to put ( eventscript, eventstring,…)

Lib.btnFuncs[1] = function()
local RunService = game:GetService("RunService") -- Gets RunService For Timing
local Camera = workspace.CurrentCamera -- Gets The Camera
local intensity = 0 -- Intensity Of Shake (Script Will Change It)
local rawIntensity = 4 -- The RawIntensity (The Base Intensity which Will make the shake lower in size)
local lastShake = tick() -- The Timing for the Last Shake
local waitTime = 6
local Sound = Instance.new("Sound", game.Workspace) -- This Sets Up The Sound
Sound.SoundId = "rbxassetid://153274423" -- Adds Sound ID
Sound.Volume = 1 -- Adds Volume

RunService.RenderStepped:Connect(function(step) -- This Function Makes The Shake
    if tick() - lastShake >= waitTime then
        intensity = 1 -- Intensity Of The Shake When It Starts (You Can Lower For Less Intense Shakes)
        lastShake = tick()
    end

    Camera.CFrame = Camera.CFrame * CFrame.new( -- Offsets The Camera
        (math.random() - 0.5) * intensity * rawIntensity,
        (math.random() - 0.5) * intensity * rawIntensity,
        (math.random() - 0.5) * intensity * rawIntensity
    )

    intensity = intensity - step -- Lowers The Intensity
    if intensity < 0 then
        intensity = 0
    end
end)

while wait(waitTime) do -- Plays The Shake Sound Every 6 Seconds (wait time amount)
    Sound:Play()
end
end)

Not sure if it works but try it :man_shrugging:

1 Like

that wont work since the shake script is local

1 Like

This should work, create a remote event in the map called TriggerShake, and then put this in event script

Lib.btnFuncs[#] = function() -- # is the button number
  Lib.Map.TriggerShake:FireAllClients()
end

Then put a local script in your map and name it LocalEventScript, and put this in there:

local RunService = game:GetService("RunService") -- Gets RunService For Timing
local Map = workspace.Multiplayer:WaitForChild("Map") -- Gets map
local Camera = workspace.CurrentCamera -- Gets The Camera
local intensity = 0 -- Intensity Of Shake (Script Will Change It)
local rawIntensity = 4 -- The RawIntensity (The Base Intensity which Will make the shake lower in size)

local Sound = Instance.new("Sound", game.Workspace) -- This Sets Up The Sound
Sound.SoundId = "rbxassetid://153274423" -- Adds Sound ID
Sound.Volume = 1 -- Adds Volume

local shake = false

RunService.RenderStepped:Connect(function(step) -- This Function Makes The Shake
    if not shake then return end
    intensity = 1
    Camera.CFrame = Camera.CFrame * CFrame.new( -- Offsets The Camera
        (math.random() - 0.5) * intensity * rawIntensity,
        (math.random() - 0.5) * intensity * rawIntensity,
        (math.random() - 0.5) * intensity * rawIntensity
    )

    intensity = intensity - step -- Lowers The Intensity
    if intensity < 0 then
        intensity = 0
        shake = false
    end
end)

Map.TriggerShake.OnClientEvent:Connect(function()
  shake = true
  delay(5, function() shake = false end)
end)
4 Likes

How i can change the shake like fast or slow, big or small

To change speed:
Change Intensity = Intensity - step to either:
Intensity = Intensity - step * 2, this will double the shaking speed
Intensity = Intensity - step / 2, this will halve the shake speed (make it slower)

To make bigger shakes just change Intensity = 1 to either a bigger or smaller number

1 Like

Uhm… Where can I change the number of shake script in the script ? ( am noob )

ehhh doesn’t actually seem to work for me

u sure cause it works for me?

Yes, is working but after i press the button, it just continue shaking. Can you fix the script so it can stop shaking ?

Ohhhh, sure