Scriptable camera working in studio but not in game

I’ve created a psuedo top-down camera for a rogue-like. It works flawlessly in Studio, but when I load up the game in the Roblox Launcher it doesn’t function at all. It’s not even applying the LookAt function, which has me thinking the entire script isn’t even being read. There are no errors that show up in the output in game, nor in Studio. I’ve made sure that the local script is in StarterPlayer.StarterPlayerScripts as well. Here is the local script:

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local Character = Player.CharacterAdded:Wait()
local HRP = Character:WaitForChild("HumanoidRootPart")
local RP = game:GetService("ReplicatedStorage")
local TweenService = game:GetService("TweenService")
local Camera = game.Workspace.CurrentCamera
local GeneratedRooms = workspace:WaitForChild("GeneratedRooms")
local CameraSwitchRE = RP.Events.CameraRoomSwitch
Mouse.TargetFilter = GeneratedRooms

local FieldOfView = 60
Camera.CameraType = Enum.CameraType.Scriptable
Camera.FieldOfView = FieldOfView
Camera.CFrame = GeneratedRooms.SpawnRoom.CameraPos.CFrame * CFrame.Angles(math.rad(-50), math.rad(0), math.rad(0))

local RunService = game:GetService("RunService")
RunService.RenderStepped:Connect(function()
	if Character then 
		local MousePos, HRPPos = Mouse.Hit.Position, HRP.Position
		local PlayerLookDirection = Vector3.new(
			MousePos.X,
			HRP.Position.Y,
			MousePos.Z
		)
		HRP.CFrame = CFrame.new(HRPPos, Vector3.new(MousePos.X, HRPPos.Y, MousePos.Z))
	end
end)

CameraSwitchRE.OnClientEvent:Connect(function(CameraPos)
	local CameraGoal = {}
	CameraGoal.CFrame = CameraPos.CFrame * CFrame.Angles(math.rad(-50), math.rad(0), math.rad(0))
	local CameraTweenInfo = TweenInfo.new(0.5, Enum.EasingStyle.Linear)
	local CameraSwitchTween = TweenService:Create(Camera, CameraTweenInfo, CameraGoal)
	CameraSwitchTween:Play()
end)

As stated, not only is it not applying the camera, but its also not applying the HRP CFrame as well. Here is are video examples of the script functioning in Studio, but not in Roblox Launcher:

If any more screenshots or videos are needed, please just request so. Any help is appreciated!

put it in startercharacterscripts

the script runs before the camera is assigned to the character, so it is resetting

I got the error RunService:UnbindFromRenderStep removed different functions with same reference name utility-focus-state-insept-TheBigBad_MOP(MyUser) 2 times.
Client sided error*
Its also no longer working in Studio when I move it to StarterCharacterScripts

I’m not too sure why it would not work in the actual Roblox Player - could be a Roblox bug or smth - and I’m not very experienced, but maybe (just a wild guess) it could be this line?

Try this if you want ig, but it’s kinda dumb

local Character = Player.Character or Player.CharacterAdded:Wait()

Edit:
this is sort of what the other guy was talkin about

1 Like

That worked? for whatever reason. I also tried disabling a beta feature that other ppl had issues with as well, I’ll turn it off and see if that was affecting it. But, this did work, however it made a random part semi transparent as well? I really hate roblox sometimes but thanks for the help :slight_smile:

wut. It worked???

(min character limit)

Yep, I re-enabled the beta feature and its functioning still as well. Also the random part was transparent bc of a wait in the client script that has nothing to do with the part, a task.wait() as well. Im guessing my character was loading in before the script was, so the script was hanging up waiting for my character to load and thus causing the appearance that it wasn’t being read at all. Thats only a guess though as Roblox isn’t the most coherent with its issues :upside_down_face: I appreciate the help all the same though, and will make sure to implement the or statement in my projects moving forward to avoid this mess. Thanks so much!

yw. it was just a shot in the dark and i learned the or thingy from some other devforum post that was on smth random. you have no idea how surprised i was when i found out that it worked

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.