CharacterAdded in a LocalScript

see if it prints ‘test’ where i put it up there

It doesn’t, the function never seems to trigger, I tried to print something before doing update() and nothing gets printed when I respawn.

idk then check if its disabled

It is not. In the same localscript I do the action for every player spawned at the moment by pressing a button. But I want it to “update” whenever someone respawns as his character’s changes reset. The button works by the way.

local function update()
print("Test")
for _, plr in pairs(game:GetService(“Players”):GetPlayers()) do
if plr.Value == true then -- or wherever the value is
for _, v in pairs(plr.Character.HumanoidRootPart:GetChildren()) do

end
end
end
end

update()

workspace.ChildAdded:Connect(function(character)
if game:GetService("Players"):GetPlayerFromCharacter(character) then
update()
end
end)

Nope. I tried printing some things and I noticed:

This one works but:

Nothing seems to be printed in this if

Hmm I also tried that, a bit weird. There must be a delay between when the character is parented into workspace and when a player’s character pointer is set to the new character. So a remedy to that would be adding a wait before the :GetPlayerFromCharacter() function. Although I don’t think thats the best programming practice.

Here's some other code you can try too
-- Variables
local players=game:GetService('Players')

-- character Added function
local function charAdd(player, char)
    print('Character was added '..char.Name)
end

-- Get existing players
plr_list=players:GetPlayers()
for _,v in pairs(plr_list) do
    v.CharacterAdded:Connect(function (char)
        charAdd(v, char)
    end)
end

-- Get new players
players.PlayerAdded:Connect(function (player)
     player.CharacterAdded:Connect(function (char)
         charAdd(player, char)
    end)
end)
7 Likes