Creating PlayerStats in ServerStorage occasionally failing

Hi! I am storing my player stats in ServerStorage, but sometimes the new Instance fails, although the Folder I store them in is there.

Code

game.Players.PlayerAdded:connect(function(player)
	
	local plrStats = Instance.new("NumberValue")
	plrStats.Name = player.Name
	plrStats.Parent = ServerStorage.PlayerMoney --PlayerMoney is the Folder 
	local isOwner = Instance.new("ObjectValue")
	isOwner.Name = "OwnsTycoon"
	isOwner.Parent = plrStats
	
	plrStats.Changed:Connect(function()
		updateCash:Fire(plrStats)
	end)
	
end)

I’ve run multiple playtests. I cannot understand why sometimes they load and sometimes not.

Thanks!
Will

isn’t player stats supposed to be a folder am i right?

is this a leaderstats or no? because if so im pretty sure they can only be made in ServerScriptService

and as he said, yes there should be a folder above

local plrStats = Instance.new("NumberValue")

It isn’t leaderstats. It’s just a storage for the money value. The actual leaderstats is a separate script that uses a StringValue. I passed the value through a BindableEvent. Don’t want to store the player money on the client.

I would suggest storing data like this in a module script because it is more reliable and may be more efficient because the server doesn’t have to create an entire instance.

Can you point me to a post or docs page that demonstrates ModuleScript data storing?

it handles it ever so slightly different in studio than in-game, out of personal experience i can tell you from personal experience that it should work completely fine in an actual game

1 Like

You’re right! Appreciate the heads up.