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)
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.
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)
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