Trying to make a character selector but the camera isnt following the character

I’m trying to make a character selector, but the camera isn’t following the character

local:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer()
end)

server

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player)
	local clone = game.Workspace.Rig:Clone()
	clone.Name = player.Name
	clone.Parent = workspace
	clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
	player.Character:Destroy()
	player.Character = clone
end)

4 Likes

Make the characters, then set the current camera mode to Scriptable, then set the CFrame of the camera to the new character.
~ Sincerely, Ihaveash0rtname
“Happy Scripting!”

2 Likes

Is there any function that can check if the player’s character was made, also would this method follow the character

local:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(workspace.CurrentCamera)
end)

server

game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, camera)
	local clone = game.Workspace.Rig:Clone()
	clone.Name = player.Name
	clone.Parent = workspace
	clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
	player.Character:Destroy()
	player.Character = clone
    camera.CameraType = Enum.CameraType.Scriptable;
    camera.CFrame = clone.HumanoidRootPart.CFrame;
    camera.CameraType = Enum.CameraType.Custom;
end)
2 Likes

i’m getting this error “attempt to index nil with ‘CameraType’”

When you say it doesn’t move with the character, is it unmovable or positioned at an incorrect angle?

the camera is unmovable and doesn’t move with the character although you can rotate it

Try

workspace.CurrentCamera.CameraSubject = [the new model humanoid rootpart]

In the localscript

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(workspace.CurrentCamera)
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
end)

didnt work

The subject must be the new model, not the current.
You could try

local Players = game:GetService("Players")
local LocalPlayer = Players.LocalPlayer
LocalPlayer.CharacterAdded:Connect(function(char)
      workspace.CurrentCamera.CameraSubject = char.HumanoidRootPart
end);

But it would be better for you to access the new character directly, consider possibly modulizing this as firing another remote event to the client giving it character information would probably work, but seems excessive.

1 Like

Tried the second option and it worked!

Code for anyone who has the same problem:

script.Parent.MouseButton1Click:Connect(function()
	game.ReplicatedStorage.RemoteEvent:FireServer(workspace.CurrentCamera)
end)

game.ReplicatedStorage.RemoteFunction.OnClientInvoke = function(player)
	workspace.CurrentCamera.CameraSubject = game.Players.LocalPlayer.Character.Humanoid
end
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(player, camera)
	local clone = game.Workspace.Rig:Clone()
	clone.Name = player.Name
	clone.Parent = workspace
	clone.HumanoidRootPart.CFrame = player.Character.HumanoidRootPart.CFrame
	player.Character:Destroy()
	player.Character = clone
	game.ReplicatedStorage.RemoteFunction:InvokeClient(player)
end)
1 Like

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