Leader stats Issue

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I’m trying to make a leaderboard on the top right which show’s cash.
  2. What is the issue? Include screenshots / videos if possible!
    So there’s now leader stats and cash showing up in the top right.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried YouTube and searching it up. I’m really confused now, if everyone is doing the same thing. What am I doing wrong.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Player = game.Players
game.Players.PlayerAdded:Connect(function()
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = leaderstats
	Cash.Value = 100
end)

In the connected function write plr and set the parent of leaderstats to plr

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = Player
	Cash.Value = 100
end)

Didn’t work

game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	
	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = leaderstats
	Cash.Value = 100
end)

You need to insert an argument in thr PlayerAdded event

Does the old player variable still exist? If so remove it

You have to parent the cash to the leaderstats folder.

AHHH. Here’s an updated script.

local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore("MyDataStore")



game.Players.PlayerAdded:Connect(function(Player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player

	local Cash = Instance.new("IntValue")
	Cash.Name = "Cash"
	Cash.Parent = leaderstats
	Cash.Value = 100
end)

It ain’t workin

OOP ignore the data store thing

Any errors in output? (Char limit)

Nope, so wat’s the issue? I’m a bit confused why it won’t work

That should work, is that the full script?

This works on my end. Where is your script located?

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

you didnt define the player in the player added event and assign value before parenting it.

Yes, some reason it ain’t showing a leader board.

Server script service, does that change anythin?

I don’t think that might be a issue… plus I think I fixed that…

i have two questions that could lead to the answer

  • what is the script’s parent?
  • what type of script is it? (LocalScript, ServerScript)

Server script and it’s in server script service.

hm, the snippets from the others who replied should fix your issue, im not sure why it is not working.

where is the player connection in the script? (Players.PlayerAdded:Connect())