FirstPersonArms work in studio but not in game

Hello! My firstPerson works in studio but not in game itself. In studio it does what it’s supoosed to, but in game it makes me have to jump to do things like walk up a staircase, or walk on the ground because of the arms going to far in the ground.

script:

local player = game.Players.LocalPlayer
local char = player.Character
local RunService = game:GetService(“RunService”)

char.Humanoid.CameraOffset = Vector3.new(-1, 0, 1)

for i, v in pairs(char:GetChildren()) do
if v:IsA(“BasePart”) and v.Name ~= “Head” then

	v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
		v.LocalTransparencyModifier = v.Transparency
	end)

	v.LocalTransparencyModifier = v.Transparency

end

end

RunService.RenderStepped:Connect(function(step)
local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
local ignoreList = char:GetChildren()

local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

if hit then
	char.Humanoid.CameraOffset = Vector3.new(-1, 0, -(char.Head.Position - pos).magnitude)
else
	char.Humanoid.CameraOffset = Vector3.new(0, 0, -2)
end

end)

maybe you’re trying to access the character before it exists. it loads/spawns faster in studio
try doing local char = player.Character or player.CharacterAdded:Wait()
also, test it using a local server from the test tab of studio rather than a normal test

I just tested this out, and it works great! Just one downside is, is that it lags a lot now. Any fix?

try using RunService.Stepped or .Heartbeat instead of RenderStepped

Still super laggy tried steped and heartbeat.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local char = player.Character
local RunService = game:GetService(“RunService”)

char.Humanoid.CameraOffset = Vector3.new(0, 0, -2)

for i, v in pairs(char:GetChildren()) do
local char = player.Character or player.CharacterAdded:Wait()
if v:IsA(“BasePart”) and v.Name ~= “Head” then

	v:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()
		v.LocalTransparencyModifier = v.Transparency
	end)

	v.LocalTransparencyModifier = v.Transparency

end

end

RunService.Heartbeat:Connect(function(step)
local ray = Ray.new(char.Head.Position, ((char.Head.CFrame + char.Head.CFrame.LookVector * 2) - char.Head.Position).Position.Unit)
local ignoreList = char:GetChildren()

local hit, pos = game.Workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)

if hit then
	char.Humanoid.CameraOffset = Vector3.new(5, 5, -(char.Head.Position - pos).magnitude)
else
	char.Humanoid.CameraOffset = Vector3.new(0, 0, -2)
end

end) Maybe I did something wrong when I changed the script.

not sure, idk what else could cause lag from this

robloxapp-20220616-1335505.wmv (1.7 MB)
here’s a little show of whats happening.