I would wrap all the code inside of the localscript into a function that’s fired once the script is enabled.
For example:
local function test()
print("Hi!")
end
test()
By wrapping your code in a function and then calling that same function, you can guarantee that your code will execute as intended when the LocalScript is enabled.
get the player’s character and get the script that’s in the character instead
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local CameraShake = Character:WaitForChild("CameraShake")
script.Parent.MouseButton1Click:Connect(function()
CameraShake.Enabled = true
end)
I would recommend against this approach. It would be better to use an event-based system to implement camera shake. You can achieve this with BindableEvents. Fire a BindableEvent when the camera needs to shake. In your Camera Shake script, connect to the BindableEvent’s Event event. You can read more about this object and how to use it here.