Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How Come my DataStore/Leaderboard won't work?

So I have a LeaderBoard that won't work and I don't get told why it won't work in the Developer Panel I don't exactly know why. What exactly could be going wrong?

---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.Value = DataStoreService:GetAsync(player.UserId) or 0
	
	local data
	local success, errormessage = pcall(function()
		data = myDataStore:GetAsync(player.UserId.."-cash")
	end)
	
	if success then
		cash.Value = data
	else
		print("There was a error whilst getting your data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local success, errormessage = pcall(function()
		myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
	end)
	
	if success then
		print("Player Data successfully saved!")
	else
		print("There was a error when saving data")
		warn(errormessage)
	end
	
end)

3 comments

0

Make sure to set the cash parent to the leaderstats folder

0

What do you mean exactly?

0

Fixxed

3 answers

✓ Accepted answer

You forgot to set the Parent for your cash value like ForeverBrown stated. If you don't do it it won't be showing in the leaderboard.

Behind the if success then if statement you can add cash.Parent = leaderstats

3 comments

0

Which "If success then?

0

Within the PlayerAdded where you create the leaderstats

0

So like this

For Flowery

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 = 0
	 
	local data
	local success, errormessage = pcall(function()
	    data = myDataStore:GetAsync(player.UserId.."-cash")
	end)
	 
	if success then
	    cash.Value = data
	else
	    print("There was a error whilst getting your data")
	    warn(errormessage)
	end
end)
	 
game.Players.PlayerRemoving:Connect(function(player)
	 
	local success, errormessage = pcall(function()
	    myDataStore:SetAsync(player.UserId.."-cash",player.leaderstats.Cash.Value)
	end)
	 
	if success then
	    print("Player Data successfully saved!")
	else
	    print("There was a error when saving data")
	    warn(errormessage)
	 end
	 
end)

2 comments

0

This?

0

FYI: I didn't look back at this post up until now but making a new post will not send a notification to all contributors in a post, if you need to get someone's attention again you should post a comment on an answer he/she posted.

This discussion is preserved as it was. New answers, comments, and votes are closed.