I want to make it that my leaderboard stops at a certain value but still saves data

welp it does not work :slightly_frowning_face: :slightly_frowning_face:

How so? what does it do? Dang character minimum…

ima be afk for 10 minutes :grinning:

hy im back ima send a video on what it does

If thats the case make it so a level/whatever can only have a certain amount of money then they have to buy an upgrade to get more money. Hopefully my idea was good if not eh.

well i would hav to talk to my partner about it

1 Like

but by any chance do u know how to do that :smile:

Nope I’m not a scripter lol I build stuff.

oh ok :smile: :smiley: :smile:

Try this code?

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

local cap = 2

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = 'leaderstats'

	local currency = Instance.new("IntValue", leaderstats)
	currency.Name = 'Rank' 
	currency.Value = 0 

	local PlayerRankId = 'Rank_'..player.UserId
	local RankData

	local s, err = pcall(function()
		RankData = MyDataStore:GetAsync(PlayerRankId)
	end)

	if s then
		currency.Value  = RankData
	else
		warn(err)
	end
	
	-- check for rank updates
	currency.Changed:Connect(function(newVal)
		if newVal > cap then
			currency.Value = cap
		end
	end)

end)

game.Players.PlayerRemoving:Connect(function(player)

	local PlayerRankId = 'Rank_'..player.UserId

	local s, err = pcall(function()
		MyDataStore:SetAsync(PlayerRankId, player.leaderstats.Rank.Value)
	end)

	if s then
		print('Stored all Player Data')
	else
		warn(err)
	end
end)

It includes a .Changed event for your Rank leaderstats. It should allow you to rank up to the cap, but not above it.

1 Like

i will try this :thinking: :face_with_raised_eyebrow:

1 Like

omg thx dude it actually works

1 Like

Awesome! Glad to help. :slight_smile:
If you need more help, feel free to post back here or reach out!

ok thks :smile: :grinning: :smiley: :grinning_face_with_smiling_eyes:

1 Like