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

I want to make it that my leaderboard stops at a certain value but still saves data this is my leaderboard script it works fine

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

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

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)
1 Like

Make the real values something like stats, then have a script update the values in leaderstats.
Why do you want this anyways?

1 Like

i want it so hackers cant get infinite money

Exploits are not able to change a server side value, make sure to have the leaderboard script as a server script. I recommend reading on how exploits and scripts work.

Ohhhhh, just do this in that script at the end:

cap = 2
while wait(1) do
if player.leaderstats.Rank >= cap then
player.leaderstats.Rank = cap
end

yes its in the serverscriptservice

Then you should be fine without exploiters getting “infinite money”

What about a serversided backdoor?

huh :thinking: :face_with_raised_eyebrow:

A serversided backdoor only happens if you have a malicious script inside your game. For example a script from the toolbox or a plugin. (I recommend to use RoDefender antivirus plugin to get rid of any backdoors)

It can still happen, if you miss something, better safe than sorry.

so were in the script should this go?

i no at the end but like were

ohhhh ok :smile: :smile: :grinning:

In sss and the value changing thing at the bottom of the leaderstats.

like here

if s then
		print('Stored all Player Data')
	else
		warn(err)
	end
cap = 2
while wait(1) do
if player.leaderstats.Rank >= cap then
player.leaderstats.Rank = cap
end
end)
local DataStoreService = game:GetService("DataStoreService")
local MyDataStore = DataStoreService:GetDataStore('MyDataStore')

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

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)

while wait(1) do
if player.leaderstats.Rank >= cap then
player.leaderstats.Rank = cap
end
end

should work

ok thx i will try that :smile:

but where is the cap = 2 thing

whoops just add that right above the while do loop.

ok i will doooo that :smile: :grinning: