Is there a more efficient way to do this?

So I am making a character choosing GUI, but the problem is that the camera does not follow the player after the new character

robloxapp-20200507-1857407.wmv (1.3 MB)

I have a local script and a script to do that, and using a remote event, I changed the character. So I thought of 2 ways to do that.

  1. Try to change the camera subject to the new humanoid after changing the character, by making a boolean value that the server changes when it’s done changing the character, and I wait in the local script until the value changes, and when it does, it changes the camera subject. But it did not work for me.
  2. Fire the event back to the client with the new character to change the camera subject to, but is this necessary to fire a remote event from the client, to the server, and then back to the client?

This is the local script:

local player = game.Players.LocalPlayer

	repeat wait() until game:GetService("ReplicatedStorage").Loaded.Value == true
	local character = player.Character or player.CharacterAdded:Wait()
	workspace.CurrentCamera.CameraSubject = player.Character:WaitForChild("Humanoid")

It should wait until the loaded value changes to true.

You can use a bindable event to send client to client messages.

1 Like

I don’t really understand how that will help me. I am trying to get the new character of the player, which I change using a remote event. Now I want from the same local script to get the new character. Don’t I have to fire a remote event back to the client with the new character? Because if I do that it works. But isn’t it less efficient to fire the remote from the server back to the client? Isn’t it better to use the same local script without firing it again?

Do you have the server script, and the client script that receives the OnClientEvent?

I believe it would be more effecient to recieve the OnClientEvent(fired by the server), because that gives an event in which would trigger more events to follow. It could be possible to do it without the OnClientEvent, but it would likely be much less effecient.

Using “wait” or “IsLoaded” or “loaded” would work too, but it would be much less effecient for players with different internet speeds, ping, and other conditions you would have to take into consideration.

Yes. And the server script receives the server event from the client in the first place, and that’s what I want to know. If I need one local script for both changing camera and character or one that changes the character using a local script, and fires the event to the server, and the server fires the event back to the client with the new character.

I would say use two scripts, or just make a function and connect it to the OnClientEvent, all in one script, if that’s what your asking? I’m slightly confused by what you mean.

1 Like

I’ll explain, here are my scripts:
First local script


Server script

	local Model = game.Workspace.Morphs.AttalTNT123
	local Morph = Model:Clone()
	Morph.Parent = workspace
	Morph.Name = player.Name
	player.Character = Morph
	game:GetService("ReplicatedStorage").ChangeChar:FireClient(player, Morph)

second local script:

	workspace.CurrentCamera.CameraSubject = character:WaitForChild("Humanoid")

I am asking, if I need these 2 local scripts, or I can use just one.

I would say, use both of them. They all work together, and seem effecient(timing wise).

1 Like