I’ve designed a system which changes your rank depending on the level you are on. The thing is, it doesn’t really work as expected.
I have a datastore which handles the rank value within the player, as well as numerous other values too:
local DS = game:GetService("DataStoreService") --- Gets Datastore Service
local CSS = DS:GetDataStore("ChaosSpleefStore_2")
local OwnedDatastore = DS:GetDataStore("OwnedDatastore")
local ownedPlaceHolder = {}
game.Players.PlayerAdded:Connect(function(plr)
local owned = {}
local ldbrd = Instance.new("Folder")
ldbrd.Name = "leaderstats"
ldbrd.Parent = plr
local CurrentlyEquipped =Instance.new("StringValue")
CurrentlyEquipped.Parent = plr
CurrentlyEquipped.Name = "CE"
local benefits = Instance.new("IntValue")
benefits.Parent = plr
benefits.Name = "Benefits"
local spleefCoins = Instance.new("IntValue")
spleefCoins.Parent = plr
spleefCoins.Name = "SpleefCoins"
local wins = Instance.new("IntValue")
wins.Parent = ldbrd
wins.Name = "Wins"
local Levels = Instance.new("NumberValue")
Levels.Parent = plr
Levels.Name = "Level"
local Rank = Instance.new("StringValue")
Rank.Parent = plr
Rank.Name = "Rank"
local XP = Instance.new("NumberValue", Levels)
XP.Name = "XP"
local XP_Limit =Instance.new("NumberValue", Levels)
XP_Limit.Name = "XP_Limit"
local playeruserid = "Player_"..plr.UserId
local data = {}
local owned
local s, e = pcall(function()
data = CSS:GetAsync(playeruserid)
owned = OwnedDatastore:GetAsync(playeruserid)
end)
if s then
if data ~= nil and owned ~= nil then
local module = require(game.ServerStorage.ListOfAllRanks)
spleefCoins.Value = data[1]
wins.Value = data[2]
benefits.Value = data[3] or 1
Levels.Value = data[4] or 1
XP.Value = data[5] or 0
XP_Limit.Value = data[6] or 30
Rank.Value = data[7] or "Basic"
else
spleefCoins.Value = 0
wins.Value = 0
end
else
error(e)
end
end)
function Save()
local players = game.Players:GetPlayers()
for _, player in pairs(players) do
local userId = "Player_"..player.UserId
local data = {player.SpleefCoins.Value, player.leaderstats.Wins.Value, player.Benefits.Value,player.Level.Value, player.Level.XP.Value, player.Level.XP_Limit.Value, player.Rank.Value}
if data then
-- wrap in pcall to handle any errors
local success, result = pcall(function()
-- SetAsync yields so will stall shutdown (@-@)
CSS:SetAsync(userId, data)
OwnedDatastore:SetAsync(userId, ownedPlaceHolder)
end)
if not success then
warn(result)
else
return true
end
end
end
end
while wait(10) do
if Save()then
print("Saved Data")
end
end
game.Players.PlayerRemoving:Connect(function(player)
Save()
if Save() then
print("Saved "..player.Name.."'s data before they left")
end
end)
game:BindToClose(Save)
That works totally fine, but the datastore doesn’t seem to set the value to anything. It just keeps it at nil despite me adding an or argument to handle the case incase the returned value is nil.
My Rank Module is this;
local module = {
["Cool"]= {
["Name"] = "Cool",
["Level"]= 2
},
["OK"]= {
["Name"] = "OK",
["Level"]= 1
},
["Nice"]= {
["Name"] = "Nice",
["Level"]= 3
},
["Sad"]= {
["Name"] = "Sad",
["Level"]= 4
},
["Noob"]= {
["Name"] = "Noob",
["Level"]= 5
}
,["Bacon"]= {
["Name"] = "Bacon",
["Level"]= 6
}
,
["Interested"]= {
["Name"] = "Interested",
["Level"]= 10
},
["Unfortunate"]= {
["Name"] = "Unforunate",
["Level"]= 20
},
["Rich"]= {
["Name"] = "Rich",
["Level"]= 30
},
["Fan"]= {
["Name"] = "Fan",
["Level"]= 50
},
["Basically A Pro"]= {
["Name"] = "Basically A Pro",
["Level"]= 100
},
["Non-Existent"]= {
["Name"] = "Non-Existent",
["Level"]= 200
},
["Jeff's Doppleganger"]= {
["Name"] = "Jeff's Doppleganger",
["Level"]= 400
},
["Chaotic"] = {
["Name"] = "Chaotic",
["Level"]= 1000
},
["Winner"] = {
["Name"] = "Winner",
["Level"]= 1200
},
["ROBLOX Fan"] = {
["Name"] = "ROBLOX Fan",
["Level"]= 1500
},
["Big Brain"] = {
["Name"] = "Big Brain",
["Level"]= 4206954
}
}
return module
And I have my rank handler script here:
local mps = game:GetService("MarketplaceService")
local vipID = 13904964
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if mps:UserOwnsGamePassAsync(plr.UserId, 13904964) then
local VIPClone = game.ServerStorage.VIP:Clone()
VIPClone.Parent = char:WaitForChild("Head")
plr:WaitForChild("Benefits").Value = 4
print("SET")
elseif plr.Name == "JeffTheEpicRobloxian" then
local VIPClone = game.ServerStorage.VIP:Clone()
VIPClone.Parent =char:WaitForChild("Head")
VIPClone.TextLabel.Text = "[VIP] [Level "..tostring(plr.Level.Value).."] "..plr.Rank.Value
plr:WaitForChild("Benefits").Value = 10
plr:WaitForChild("SpleefCoins").Value += 100
game.ReplicatedStorage.ShowMoneyEffect:FireClient(plr, 100)
print("SET")
plr.Level:GetPropertyChangedSignal("Value"):Connect(function()
VIPClone.TextLabel.Text = "Level Up"
local rank
for i, V in pairs(require(game.ServerStorage.ListOfAllRanks)) do
if plr.Level.Value >= V.Level then
rank = V.Level
end
end
plr.Rank.Value = rank
wait(2)
VIPClone.TextLabel.Text = "[VIP] [Level "..tostring(plr.Level.Value).."] "..plr.Rank.Value
end)
else
local TagClone = game.ServerStorage.Tag:Clone()
TagClone.TextLabel.Text = "[Level "..tostring(plr.Level.Value).."] "..plr.Rank.Value
TagClone.Parent = char:WaitForChild("Head")
print("SET")
plr.Level:GetPropertyChangedSignal("Value"):Connect(function()
TagClone.TextLabel.Text = "Level Up"
local rank
for i, V in pairs(require(game.ServerStorage.ListOfAllRanks)) do
if plr.Level.Value >= V.Level then
rank = V.Level
end
end
plr.Rank.Value = rank
TagClone.TextLabel.Text = "[Level "..tostring(plr.Level.Value).."] "..plr.Rank.Value
end)
end
end)
end)
I don’t know what the issue is. Help?