Camera script working in studio but not in game

Made this camera script

local plr = game.Players.LocalPlayer
local chr = script.Parent
local UIS = game:GetService('UserInputService')
local mouse = plr:GetMouse()
local RS = game:GetService("RunService")


   
plr.PlayerGui:WaitForChild("Bars").Enabled = true

UIS.MouseBehavior = Enum.MouseBehavior.LockCenter

local BG = Instance.new("BodyGyro")
BG.P = 10000000
BG.Parent = chr:WaitForChild("HumanoidRootPart")
BG.MaxTorque = Vector3.new(0,math.huge,0)



RS.Stepped:Connect(function()
   local hum = chr:FindFirstChild("Humanoid")
   hum.CameraOffset = Vector3.new(4,1,0)
   BG.CFrame = mouse.Origin
end)

local on = true

UIS.InputBegan:Connect(function(input, GPE)
   if not GPE and input.KeyCode == Enum.KeyCode.LeftShift then
   	if on == false then
   		UIS.MouseBehavior = Enum.MouseBehavior.Default
   		on = true
   	else
   		UIS.MouseBehavior = Enum.MouseBehavior.LockCenter
   		on = false
   	end
   end
end)

and it works fine in studio:

in game it loads nothing however

camera script is located in starterchrscripts and is local

try local chr = plr.Character or plr.CharacterAdded:Wait()