Here are the relavent scripts for reference:
SetCamera (LocalScript)
-- This script is responsible for setting the player camera --
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
player.CharacterAdded:Wait()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = workspace:WaitForChild("CameraBox").CFrame
print("Camera has been set properly.")
TestScript (Server Script)
-- Necessary services --
local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local ServerScriptService = game:GetService("ServerScriptService")
-- Script Module Folders --
local Modules = ServerScriptService:WaitForChild("Modules")
local PlayerModules = Modules:WaitForChild("PlayerModules")
local CharacterModules = Modules:WaitForChild("CharacterModules")
local WorldModules = Modules:WaitForChild("WorldModules")
-- Player Modules --
local PlayerCameraBox = require(PlayerModules:WaitForChild("PlayerCameraBox"))
local PlayerCameraBoxDestroyer = require(PlayerModules:WaitForChild("PlayerCameraBoxDestroyer"))
-- Character Modules--
local PlayerCharacter = require(CharacterModules:WaitForChild("PlayerCharacter"))
-- World Modules --
local World = require(WorldModules:WaitForChild("World"))
local WorldBuilder = require(WorldModules:WaitForChild("WorldBuilder"))
local WorldDestroyer = require(WorldModules:WaitForChild("WorldDestroyer"))
local WorldDescriptor = require(WorldModules:WaitForChild("WorldDescriptor"))
local WorldPlatformDefiner = require(WorldModules:WaitForChild("WorldPlatformDefiner"))
-- Folders --
local Platforms = ServerStorage:WaitForChild("Platforms")
local CharacterModels = ServerStorage:WaitForChild("CharacterModels")
local world = World.new("Tutorial", Platforms:WaitForChild("BaseGrassPlatform"), 4)
local worldBuilder = WorldBuilder.new(world)
worldBuilder:build(Platforms)
local worldModel = workspace:WaitForChild(world:getWorldName())
WorldPlatformDefiner.setPlatformCharacteristic(world, worldModel)
local worldDescriptor = WorldDescriptor.new(worldModel)
local cameraBox = PlayerCameraBox.new(worldModel, Vector3.new(world:getPlatformModel().PrimaryPart.Position.X,
worldDescriptor:describeWorldHeight() / 2,
-40), Vector3.new(0, 180, 0))
cameraBox:setCameraBox()
Players.CharacterAutoLoads = false
Players.PlayerAdded:Connect(function(player)
local playerCharacter = PlayerCharacter.new(player, CharacterModels:WaitForChild("DefaultCharacter"))
playerCharacter:load()
player.Character:SetPrimaryPartCFrame(workspace:WaitForChild("Tutorial"):WaitForChild("BaseGrassPlatform").Spawn.CFrame)
end)
PlayerCameraBox (Module Script)
local PlayerCameraBox = {}
PlayerCameraBox.__index = PlayerCameraBox
local Modules = script.Parent.Parent
local WorldModules = Modules.WorldModules
local WorldModelManager = require(WorldModules.WorldModelManager)
local WorldDescriptor = require(WorldModules.WorldDescriptor)
function PlayerCameraBox.new(worldModel, position, rotation)
local playerCameraBox = {}
playerCameraBox._worldModelManager = WorldModelManager.new(worldModel)
playerCameraBox._position = position
playerCameraBox._rotation = rotation
setmetatable(playerCameraBox, PlayerCameraBox)
return playerCameraBox
end
-- Sets the camera box relative to the world model --
function PlayerCameraBox:setCameraBox()
local worldDescriptor = WorldDescriptor.new(self._worldModelManager)
local worldModel = self._worldModelManager:getWorldModel()
local cameraBox = Instance.new("Part")
cameraBox.Name = "CameraBox"
cameraBox.Size = Vector3.new(2, 2, 2)
cameraBox.Position = self._position
cameraBox.Rotation = self._rotation
cameraBox.Anchored = true
cameraBox.Transparency = 1
cameraBox.Parent = workspace
end
return PlayerCameraBox
Anyway, with these scripts, my issue as the title suggests is with the player camera. The player camera works as expected in Roblox studio. Here is a screenshot of how I intend for it to work.
However, when I try publishing the game to roblox to see how it would play out outside of roblox studio, the camera does not set properly, but everything else does. Here is a screenshot of what it looks like in Roblox outside of Roblox Studio.
How do I resolve this issue? I tried removing the camera module from Player Module and while that stopped the camera from focusing on the player from behind, which is also not what I was intending as I want this game to have a 2D perspective, it still doesn’t go where it’s supposed to.