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

Why does my leaderstat show up with just Cash, Value and Kills?

Here is my opening script to get my leaderstat; however when I test it the three options are Cash, Value and Kills. The Cash and Value are linked as the number is the same and changes as one. It creates a prestige under the player.leaderstats, but doens't show up


local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("KillsSaveSystem")
local ds2 = DataStore:GetDataStore("CashSaveSystem")
local ds3 = DataStore:GetDataStore("PrestigeSaveSystem")

game.Players.PlayerAdded:connect(function(player)
	local leader = Instance.new("Folder",player)
	leader.Name = "leaderstats"
	
	local Kills = Instance.new("IntValue",leader)
	Kills.Name = "Kills"
	Kills.Value = ds:GetAsync(player.UserId) or 0
	ds:SetAsync(player.UserId, Kills.Value)
	Kills.Changed:connect(function()
		ds:SetAsync(player.UserId, Kills.Value)			
	end)
	
	local Cash = Instance.new("IntValue",leader)
	Cash.Name = "Cash"
	Cash.Value = ds2:GetAsync(player.UserId) or 0
	ds2:SetAsync(player.UserId, Cash.Value)
	Cash.Changed:connect(function()
		ds2:SetAsync(player.UserId, Cash.Value)			
	end)
	
	local Prestige = Instance.new("IntValue",leader)
	Prestige.Name = "Prestige"
	Prestige.Value = ds3:GetAsync(player.UserId) or 0
	ds3:SetAsync(player.UserId, Prestige.Value)
	Prestige.Changed:connect(function()
		ds3:SetAsync(player.UserId, Prestige.Value)			
	end)
end)
	



game.Players.PlayerRemoving:connect(function(player)
	ds:SetAsync(player.UserId, player.leaderstats.Kills.Value)
	ds2:SetAsync(player.UserId, player.leaderstats.Cash.Value)
	ds3:SetAsync(player.UserId, player.leaderstats.Prestige.Value)
end)

2 comments

0

instead of using 3 datastores for each value, store a table into only 1 datastore as your problem might be making too many calls to the datastore service (there are limits: https://www.robloxdev.com/articles/Datastore-Errors)

0

^that may or may not fix your problem but its best to take care of it before proceeding with your data saving system

1 answer

Hi, I'm BlackOrange and I will be giving you a template.

Here is your template to display the stats on the leaderboard. You will have to add the datastore.

game.Players.PlayerAdded:Connect(function(plr)
	local LS = Instance.new('Model')
	LS.Name = 'leaderstats'
	LS.Parent = plr

	local Kills = Instance.new('IntValue')
	Kills.Name = 'Kills'
	Kills.Parent = LS

	local Cash = Instance.new('IntValue')
	Cash.Name = 'Cash'
	Cash.Parent = LS

	local Prestige = Instance.new('IntValue')
	Prestige.Name = 'Prestige'
	Prestige.Parent = LS
end)

I do not understand your question, please do make your script a little more organized and write in proper sentences.

Hopefully this will help.

Best of luck developer!

PS: Also try to have only 1 DataStore.

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