Character added event not firing?

That is my code above, for some reason it will not print that in the output. Is there any reason why? It doesn’t print “test3” in the output when I play the game.

1 Like

Is there any errors in the output?

Nope no errors. I’m so confused.

There is a chance that their character exists before the method is fired. Consider checking if createStats yields thread at any time. (Such as DataStore:GetAsync)

You can fix this by simply just checking if the character exists, then call your function that you’re passing to CharacterAdded with the already existing character.

local function characterAdded(character)
    print("test3")

    character:WaitForChild("Humanoid", 7).WalkSpeed = 16 + ... --// and so on
end

players.PlayerAdded:Connect(function(plr)
    createStats(plr)

    local kills = plr.leaderstats.Kills
    local spree = plr.leaderstats.Spree
    local topSpree = plr.leaderstats.TopSpree

    print("test2")

    if (plr.Character) then
        characterAdded(plr.Character)
    end

    plr.CharacterAdded:Connect(characterAdded)
end)
2 Likes

Oh your right, since the create stats uses datastores… thank you so much for the help. That was a mistake on my end.

Also I believe you should be doing WalkSpeed = ... instead of WalkSpeed.Value = ... because WalkSpeed is a number property not a NumberValue instance

Yeah I sort of wrote alot of code without testing much, I’d recently started syncing code from vs code and making stuff offline.