I want my player to join the game, and instantly be in freecam mode. I tried making my player not spawn, and put it in freecam mode, but the camera just locks and can’t move.
How can I make it so that the player joins the game, and is instantly in freecam, without a loaded in character? (My game has teams, and I want my players character to load in when it is in the players team (when the game starts), and when the game hasn’t started I want the player to be in the spectator team, in freecam mode.)
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local camera = game.Workspace.CurrentCamera
-- Function to enable freecam
local function enableFreecam()
camera.CameraType = Enum.CameraType.Scriptable
camera.CFrame = CFrame.new(Vector3.new(0, 50, 0)) -- Adjust the position as needed
end
-- Function to disable freecam and load character
local function disableFreecam()
camera.CameraType = Enum.CameraType.Custom
player:LoadCharacter()
end
-- Enable freecam when the player joins
enableFreecam()
-- Listen for team changes to disable freecam
player:GetPropertyChangedSignal("Team"):Connect(function()
if player.Team.Name ~= "Spectator" then
disableFreecam()
end
end)
Script (Place in ServerScriptService).
local Players = game:GetService("Players")
local Teams = game:GetService("Teams")
-- Assign players to the Spectator team when they join
Players.PlayerAdded:Connect(function(player)
player.Team = Teams:FindFirstChild("Spectator")
end)
-- Function to start the game and switch teams
local function startGame()
for _, player in pairs(game.Players:GetPlayers()) do
player.Team = Teams:FindFirstChild("PlayingTeam") -- Replace with your actual team name
end
end
-- Call startGame() when you want to start the game
These scripts should help the player start in free cam mode.
It seems to be working, makes the camera cframe change, but I still can’t move the camera around. And workspace seems like it isn’t being loaded in for some reason.
This is what my camera sees on the server (same position as client):
local function freecam(camera : Camera, rotationSpeed : number)
local rotationSpeed = rotationSpeed or 1
camera.CameraType = Enum.CameraType.Scriptable
local keys = {
["W"] = CFrame.new(0, 0, -1),
["S"] = CFrame.new(0, 0, 1),
["A"] = CFrame.new(-1, 0, 0),
["D"] = CFrame.new(1, 0, 0),
["Q"] = CFrame.new(0, -1, 0),
["E"] = CFrame.new(0, 1, 0),
}
return UIS.InputBegan:Connect(function(input, isTyping)
if isTyping then return end
for i, v in pairs(keys) do
if input.KeyCode == Enum.KeyCode[i:upper()] then
local keyUp
local endedEvent = UIS.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if input.KeyCode == Enum.KeyCode[i:upper()] then
keyUp = true
end
end)
repeat
camera.CFrame *= v
wait()
until
keyUp
endedEvent:Disconnect()
break
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
UIS.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
local connection = UIS.InputChanged:Connect(function(input)
local delta = -input.Delta * rotationSpeed
camera.CFrame *= CFrame.Angles(math.rad(delta.Y), math.rad(delta.X), 0)
end)
local endedEvent
endedEvent = UIS.InputEnded:Connect(function(input, isTyping)
if isTyping then return end
if input.UserInputType == Enum.UserInputType.MouseButton2 then
connection:Disconnect()
UIS.MouseBehavior = Enum.MouseBehavior.Default
endedEvent:Disconnect()
end
end)
end
end
end)
end
freecam(workspace.CurrentCamera)