Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

SOLVED Game is literally unplayable with these team change camera issues?

Ive been trying to make a team change gui, where when you first join the game you are looking over a baseplate, due to camera manipulation. Then when you change the team, you spawn with the normal roblox camera and no camera manipulation. That second part does not work. The issue is that when I join a team my camera is not following the player- I cant even see the player on the screen. Here are the scripts

-- Camera 
local TeamChoose = script.Parent.Parent
local confirm = script.Parent.Parent.Teamchange.Frame.Light.Button --Select button
local confirm2 = script.Parent.Parent.Teamchange.Frame.Dark.TextButton --Select button

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

repeat wait() until Player.Character

Camera.CameraType = "Scriptable"
Camera.CFrame = game.Workspace.CamPart.CFrame


confirm.MouseButton1Click:Connect(function()
	Camera.CameraType = "Custom"
	game.Workspace.CamPart:Destroy()
end)

confirm2.MouseButton1Click:Connect(function()
	Camera.CameraType = "Custom"
	game.Workspace.CamPart:Destroy()
end)

And the team change (there are two of these, one for each team)

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local player = script.Parent.Parent.Parent.Parent.Parent
local TeamChoose = script.Parent.Parent
local confirm = script.Parent.Button
local confirm2 = script.Parent.Parent.Dark.TextButton

script.Parent.MouseButton1Click:Connect(function()
	script.Parent.Button.Visible = false
	script.Parent.Parent.Light.Button.Visible = true
end)


script.Parent.Button.MouseButton1Click:Connect(function()
	player.Team = game.Teams.Light
	TeamChoose:TweenPosition(UDim2.new(0.25, -0,-1, -0),"Out","Quint",1,true)
	player.Character.Humanoid.Health = 0
end)


Thanks in advance

3 answers

✓ Accepted answer

in addition to what @torchmaster101 said, you also need to change the camera subject back to the player's humanoid, because by default the camera subject for a game is the player's humanoid, so add this instead of deleting the part,

confirm.MouseButton1Click:Connect(function()
	Camera.CameraSubject = player.Character:WaitForChild("Humanoid")
end)

confirm2.MouseButton1Click:Connect(function()
	Camera.CameraSubject = player.Character.Humanoid
end)

3 comments

0

changing camera subject prevents the part from getting destroyed when you reswitch teams

0

Thanks guys! Just about to try this out!

0

I think I changed it, but it still doesn't work. Maybe check this script below?

So, my personal advice with changing a camera type is to not just type in something like:

Camera.CameraType = "Scriptable"

But instead something like:

repeat wait()
	Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable

Camera Types are an Enumeration, so I recommend typing it like this instead of typing it as a string and in one line.

Also, line 9 of the first script confuses me. Are you trying to get the character? If you are, you can just do something like:

local character = player.Character or player.CharacterAdded:Wait()

Comment back if this doesn't fix your problem or you have any questions.

5 comments

0

The repeat is important cause it helps prevent errors when switching camera types

0

Yeah Ill try this thanks alot :)

0

Yeah i think i am trying to get the character

0

Oh ok, then I recommend using what I typed, but if this works for you then you can keep it :)

0

I will try this out tomorrow

local TeamChoose = script.Parent.Parent
local confirm = script.Parent.Parent.Teamchange.Frame.Light.Button
local confirm2 = script.Parent.Parent.Teamchange.Frame.Dark.TextButton

local Camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer

repeat wait() until Player.Character

repeat wait()
    Camera.CameraType = Enum.CameraType.Scriptable
until Camera.CameraType == Enum.CameraType.Scriptable
Camera.CFrame = game.Workspace.CamPart.CFrame


confirm.MouseButton1Click:Connect(function()
    Camera.CameraSubject = Player.Character:WaitForChild("Humanoid")
end)

confirm2.MouseButton1Click:Connect(function()
    Camera.CameraSubject = Player.Character.Humanoid
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.