Camera script working in studio, but not in the game if you launch it from the website

ok, so, i wanted to create a roblox script that would make the camera work like the one seen in baldi’s basics, so you can’t look up and down, and when the space is held the character looks back, and all of that works perfectly in the studio, except for when you launch it in roblox, the cursor in the menus will be stuck, and even if you launch the game through the menu somehow, the camera will be at the 0,0,0 position instead of the normal one, and what’s even weirder, all of that happens only when you launch the game from the site, when you launch the game from the roblox client everything works
so yeah i don’t know what to do, here’s the script

local camera = workspace.CurrentCamera
local userInputService = game:GetService("UserInputService")
local runService = game:GetService("RunService")
local isSpacePressed = false
local player = game:GetService("Players").LocalPlayer
local playerScripts = player:WaitForChild("PlayerScripts")
local playerModule = require(playerScripts:WaitForChild("PlayerModule"))
local movementController = playerModule:GetControls()

camera.CameraType = Enum.CameraType.Scriptable

local sensitivity = workspace.GlobalValues.Sensitivity

local function updateCamera()
	local delta = userInputService:GetMouseDelta()
	local rotation = CFrame.Angles(0, math.rad(-delta.x * sensitivity.Value), 0)
	local currentRotation = camera.CFrame - camera.CFrame.Position
	local newRotation = rotation * currentRotation
	local newLookVector = newRotation.LookVector * Vector3.new(1, 0, 1)
	camera.CFrame = CFrame.new(camera.CFrame.Position, camera.CFrame.Position + newLookVector)
end

local function onInputBegan(input, processed)
	if not processed and input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Space then
		movementController.moveFunction = function(player, direction, relative)
			player.Move(player, -direction, relative)
		end
		camera.CFrame = CFrame.new(camera.CFrame.Position, camera.CFrame.Position - camera.CFrame.LookVector * Vector3.new(1, 0, 1))
	end
end

local function onInputEnded(input, processed)
	if not processed and input.UserInputType == Enum.UserInputType.Keyboard and input.KeyCode == Enum.KeyCode.Space then
		movementController.moveFunction = function(player, direction, relative)
			player.Move(player, direction, relative)
		end
		camera.CFrame = CFrame.new(camera.CFrame.Position, camera.CFrame.Position - camera.CFrame.LookVector * Vector3.new(1, 0, 1))
	end
end

userInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
userInputService.InputBegan:Connect(onInputBegan)
userInputService.InputEnded:Connect(onInputEnded)

runService.RenderStepped:Connect(updateCamera)

I think it’s probably due to animations only being performed by Local scripts.
I might be totally wrong, but when testing in Studio all Local and Server scripts are handled by your computer, so some Server scripts will function fine as doing Local script work, but on the Server they act completely as Server scripts.

ok i found the issue lmaooo, this was because of

camera.CameraType = Enum.CameraType.Scriptable

this camera code was generated by chatgpt, and also fixed by it too lol

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