So I am trying to make a camera shake when an event is fired. The script I am using works when the CameraSubject is a humanoid, however I put it as a part as it follows a ship model. Because of this, “CameraOffset” does not exist under the part so I am wondering if there is another way to make the camera shake.
I have tried putting a humanoid as a child of the part and setting it as the CameraSubject, but it doesn’t work. Here is the script:
local Player = game.Players.LocalPlayer
local RunService = game:GetService("RunService")
local Folder = game.Workspace.Ships:FindFirstChild(Player.Name)
local Camera = Folder.Ship.CamPart
function ShakeCamera()
local now = tick()
local bobbleX = math.cos(now * 9) / 6
local bobblyY = math.abs(math.sin(now * 12)) / 3
local bobble = Vector3.new(bobbleX, bobblyY, 0) * 5
Camera.CameraOffset = Camera.CameraOffset:Lerp(bobble, .25)
end
game.ReplicatedStorage.Cannons.Fire.OnClientEvent:Connect(function(isShaking)
if isShaking then
RunService:BindToRenderStep("CameraShake", Enum.RenderPriority.Camera.Value + 1, ShakeCamera)
else
RunService:UnbindFromRenderStep("CameraShake")
end
end)
Any help would be appreciated, thank you :).