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

How do I make (PlayerFromATable).CharacterAdded work in a LocalScript?

Hello. I have this spectate script and I'm trying to fix a certain part of this script where the camera doesn't focus back on the player after they die and respawn. The problem is I can't seem to make CharacterAdded work.

Here's the part of the script:

playerList[position].CharacterAdded:Connect(function(char)
    --repeat
      	print("test")
        updateCamera(playerList[position])
    --until char.Humanoid.Health ~= 0
end)

I already tried fixing it by creating a name string for the player but it still didn't work.

It looked something like this:

local playerName = playerList[position].Name

game.Players.playerName.CharacterAdded:Connect(function(char)
    --repeat
 		print("test")
  		updateCamera(playerList[position])
    --until char.Humanoid.Health ~= 0
end)

1 comment

0

Use RemoteEvents.

1 answer

You can't do Players.playerName as it will look for something named playerName. You need to do

game.Players[playerName].CharacterAdded:Connect(function(char)

Please use output for these types of issues, as your script would have errored and told you "playerName is not a valid member of workspace"

3 comments

0

i haven't tested but you're right.

0

Unfortunately this didn't helped either. The camera still stays on the same spot where the player died.

0

Does output give you any errors

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