What do you want to achieve? Keep it simple and clear!
I’m trying to make leaderstats in the StarterCharacterScripts but the cash value doesn’t show in the leaderstats, it works in the ServerScriptService. I just want to clarify if only works in certain areas or if I’m doing something wrong.
What is the issue? Include screenshots / videos if possible!
starter character scripts will load the scripts once the character has been loaded/respawned. the reason why it doesn’t work is because the PlayerAdded event has already been fired when the script is put into the character. also, this script will trigger for every single player, not just the player who has the script. this means for every player that is currently in the server it will add a leaderstats folder to the player that joined
you cannot yield the PlayerAdded event. you would have to just put the script in workspace, ServerScriptService, or if you want to use StarterPlayerScripts then the code would have to be changed into
local player = script.Parent.Parent
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local cash = Instance.new("IntValue", leaderstats)
cash.Name = "Cash"
cash.Value = 0