Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago

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)
0
Use RemoteEvents. camomileex0 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

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"

0
i haven't tested but you're right. quotist 0 — 3y
0
Unfortunately this didn't helped either. The camera still stays on the same spot where the player died. quotist 0 — 3y
0
Does output give you any errors DietCokeTastesGood 111 — 3y
Ad

Answer this question