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

Why won't characteradded execute?

Asked by 10 years ago

Title pretty much says it all.

game.Players.PlayerAdded:connect(function(player)   
    createstats(player)
    cloneready(player)
    clonespawned(player)
    clonefirst(player)
    updategui()
    print("Functions executed") -- this does print
    player.CharacterAdded:connect(function(character)
        print("Character added") -- This doesn't print
        logo(player)
        player.PlayerGui.SpawnGui.BG.Visible = true
        character.Humanoid.Died:connect(function()
            died(player)
        end)
    end)
end)

I get no errors in the output. CharacterAdded has been a very finicky thing for me before now and I'd really like to know if I'm just using it wrong.

edit: After doing some more testing in my place, I found out that characteradded fires when the player respawns, but not on the first spawn. I am using a test server rather than play solo, so characteradded should work the first time, but it doesn't...

edit2: I also went to the real place on my profile and played it there. The characteradded function still didn't fire when I spawned, but did after I died.

0
Do any of the functions above your CharacterAdded statement yeild (use `wait` or just stop the script in general somehow?) User#2 0 — 10y
0
They do, but I have prints at the end of each function and of of them do print. Everything runs fine until the characteradded function, then it just stops until the player dies for the first time and respawns. LightArceus 110 — 10y

1 answer

Log in to vote
0
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

The first spawn most likely occurs before you can attach the CharacterAdded event.

The cleanest way to fix this is to make your CharacterAdded a function on its own and simulate that CharacterAdded event right after you attach it.

function NewCharacter(character,player)
    print("Character added") -- This doesn't print
    logo(player)
    player.PlayerGui.SpawnGui.BG.Visible = true
    character.Humanoid.Died:connect(function()
        died(player)
    end)
end

game.Players.PlayerAdded:connect(function(player)   
    createstats(player)
    cloneready(player)
    clonespawned(player)
    clonefirst(player)
    updategui()
    print("Functions executed") -- this does print
    player.CharacterAdded:connect(function(character)
        NewCharacter(character,player);
    end)
    if player.Character then
        -- We were too late getting the
        -- CharacterAdded attached--there already
        -- was a character, so we need to simulate
        -- the event firing here.
        NewCharacter(player.Character,player);
    end
end)
Ad

Answer this question