Can you make Leaderstats in StarterCharacterScripts

  1. 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.

  2. What is the issue? Include screenshots / videos if possible!

Script:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = 0
	cash.Parent = leaderstats
end)

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

Thanks, but to fix the issue, I tried putting a wait() or if statement those didn’t work. What would I have to yield the PlayerAdded event.

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

The leaderstats script doesn’t actually work when I put in StarterPlayerScripts, but thanks for the clarification.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.