The CharacterAdded stopped working on localscripts? Is this a recent update?
My code(below) always worked and ever since the DataStores went down, it stopped.
P.S code located in the LocalScript that is a descendant of the Backpack of the player
local Player = game.Players.LocalPlayer
Player.CharacterAdded:Connect(function()
print("Works") --// Doesn't print, although it worked previously
end)
Not a lot of context being provided here.
What exactly are you using CharacterAdded in the Local Script for? Whose character is it you want it to fire on? What is supposed to happen? When did the issue begin?
Please provide more information if you want any help.
I think the question itself is straight forward. My CharacterAdded event won’t work in local scripts, although they worked perfectly fine before. I tried looking for the answers on the web, but didn’t find anything regarding that question.
You provided very little information before editing. You can’t really ask for support and expect much help with two very bland sentences, that don’t explain much of the problem, besides the fact it’s ‘not working’.
Going by the recent edit in the OP.
When testing a Local Script myself that’s a descendant of the player’s backpack. (even the exact code you provided) The event fires for me every-time the script is replicated into the Backpack of the player. Could anything be yielding the script before the script is able to connect the event? When is it being inserted into the backpack?
If it’s a script inserting it, keep in mind a player’s backpack resets every-time the character is added. So thus the script could be getting removed every-time. That or it’s not inserting it before the character is added on the server. If it’s parented under ‘StarterPack’, then as mentioned before the event fires for me every-time the script replicates.
CharacterAdded still works on the client. You may find it doesn’t work when initially joining the game as the character is added to the game before the CharacterAdded event is setup.
To solve this, I would recommend having a separate local script in StarterCharacterScripts, then using a Bindable Event (or modular framework) to trigger the effect in your current script.
You could also do something like this, however it is not as efficient and accurate:
local player = game.Players.LocalPlayer
local characterAddedAlready = true
local function characterAdded()
characterAddedAlready = true
end
player.CharacterAdded:Connect(function()
characterAdded()
end)
wait(1)
if not characterAddedAlready then
characterAdded()
end
Also, you shouldn’t be using the Backpack to store LocalScripts. Use the services Roblox provide: StarterPlayerScripts, StarterCharacterScripts and StarterGui.
One more thing I’d like to mention is that it either works or not. The script itself is stationary and is never moved anywhere. Also there are more scripts that stopped working that are located under PlayerGui. One example of how I used CharacterAdded is to display the Players’ currency whenever their character is loaded in the game.
Anything which impacts the client’s join time, such as the introduction of a larger map, more GUIs, client-code, etc. You shouldn’t need to worry about this though if your client code is setup correctly.
As previously mentioned earlier. If the script is under a ScreenGui. The event won’t fire the first time the character is added. But it will proceed to fire every-time after that as long as the ‘ResetOnSpawn’ property is set to false.
Also mentioned before. The player’s backpack resets everytime the player’s Character is reset. So if the script is not being added after the player dies, it will not fire at all as the script is no longer being inserted into the backpack. Unless of course it is parented under StarterPack.