Hey, I was making a non-group ranking system for a game and im having a problem on changing the rank after reaching the RequiredToRank stat:
So what I want to achieve is once the players RequiredToRank stat reaches the required amount to get a new rank, it should change the Rank stat to the next rank but totally not working
Stats Script:
local datastore = game:GetService('DataStoreService'):GetDataStore('RS12345')
game.Players.PlayerAdded:Connect(function(p)
local stat = Instance.new('Folder')
stat.Name = 'leaderstats'
stat.Parent = p
local key1 = 'rank'
local key2 = 'required'
local rank = Instance.new('StringValue')
rank.Name = 'Rank'
rank.Parent = stat
rank.Value = datastore:GetAsync(key1) or 'Recruit'
local required = Instance.new('IntValue')
required.Name = 'RequiredToRank'
required.Parent = stat
required.Value = datastore:GetAsync(key2) or 0
while task.wait(2) do
required.Value += 1
end
end)
RankUp Script:
local ranks = {
[1] = {Rank = 'Private'},
[3] = {Rank = 'Private First Class'},
[5] = {Rank = 'Corporal'},
[10] = {Rank = 'Sergeant'},
[15] = {Rank = 'Staff Sergeant'},
[25] = {Rank = 'Sergeant First Class'},
[30] = {Rank = 'Master Sergeant'},
[35] = {Rank = 'First Sergeant'},
[45] = {Rank = 'Sergeant Major'},
[60] = {Rank = 'Command Sergeant Major'},
[80] = {Rank = 'Second Lieutenant'},
[100] = {Rank = 'Lieutenant'}
}
local datastore = game:GetService('DataStoreService'):GetDataStore('RS12345')
game.Players.PlayerAdded:Connect(function(p)
local stat = p:WaitForChild('leaderstats')
local rank = stat.Rank
local require = stat:WaitForChild('RequiredToRank')
for required,nextrank in pairs(ranks) do
if require.Value >= required then
rank.Value = nextrank.Rank
end
if require.Value <= required and rank.Value == nextrank.Rank then
rank.Value = nextrank.Rank
end
end
end)
game.Players.PlayerRemoving:Connect(function(p)
local rank = p.leaderstats.Rank
local required = p.leaderstats.RequiredToRank
local key1 = 'rank'
local key2 = 'required'
if rank and required then
datastore:SetAsync(key1,rank.Value)
datastore:SetAsync(key2,required.Value)
end
end)