So, i don’t know why this happens but seems like it breaks somehow whenever an Data Value from a player changes, for example:
When a player touch the “Winner” Part, the part apply values to his stats and then this appears on the output:
(This error may have something to do with Exp and MaxExp data values? since before they where updating normally when Exp > MaxExp
but now they don’t and Exp value just keep growing without a limit based on MaxExp)
I don’t know what is wrong since i was using the same exact DataStore script before and it was working perfectly fine.
In any case, this is the datastore script i am using right now:
local DataStore2 = require(game:GetService("ServerScriptService").DataStore2) -- Require the DataStore Module using the name
local MainKey = "Key1"
DataStore2.Combine(MainKey, "Stats")
local function CreateDataTable()
local PlayerData = {
Stats = {
["Gold"] = 0;
["Silver"] = 0;
["Bronze"] = 0;
["Rushies"] = 0;
["Level"] = 1;
["Exp"] = 0;
["MaxExp"] = 100;
};
}
return PlayerData
end
game:GetService("Players").PlayerAdded:Connect(function(plr) -- WHEN PLAYER JOINS --
local PlayerData = DataStore2(MainKey, plr):GetTable(CreateDataTable()) -- GetPlayersDataTable
local Folder = Instance.new("Folder") -- CURRENT STATS --
Folder.Name = "PlayerStats"
local Gold = Instance.new("IntValue")
Gold.Name = "Gold"
local Silver = Instance.new("IntValue")
Silver.Name = "Silver"
local Bronze = Instance.new("IntValue")
Bronze.Name = "Bronze"
local Rushies = Instance.new("IntValue")
Rushies.Name = "Rushies"
local Level = Instance.new("IntValue")
Level.Name = "Level"
local Exp = Instance.new("IntValue")
Exp.Name = "Exp"
local MaxExp = Instance.new("IntValue")
MaxExp.Name = "MaxExp"
local Leaderboard = Instance.new("Folder") -- LEADERSTATS STUFF --
Leaderboard.Name = "leaderstats"
local LeaderboardWins = Instance.new("IntValue")
LeaderboardWins.Name = "Wins"
LeaderboardWins.Value = Gold.Value
local LeaderboardLv = Instance.new("IntValue")
LeaderboardLv.Name = "Lv"
LeaderboardLv.Value = Level.Value
local StatsData = DataStore2("Stats", plr)
local function UpdateAllStats(UpdatedStats)
Gold.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Gold"] -- Sets value you've made to correspond with data table
Silver.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Silver"]
Bronze.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Bronze"]
Rushies.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Rushies"]
Level.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Level"]
Exp.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Exp"]
MaxExp.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["MaxExp"]
LeaderboardWins.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Gold"]
LeaderboardLv.Value = DataStore2(MainKey, plr):GetTable(UpdatedStats)["Stats"]["Level"]
end
UpdateAllStats(PlayerData.Stats) -- Calls the function and updates player data to appropriate values
DataStore2(MainKey, plr):OnUpdate(UpdateAllStats) -- Calls when updated
Folder.Parent = plr
Gold.Parent = Folder
Silver.Parent = Folder
Bronze.Parent = Folder
Rushies.Parent = Folder
Level.Parent = Folder
Exp.Parent = Folder
MaxExp.Parent = Folder
Leaderboard.Parent = plr
LeaderboardWins.Parent = Leaderboard
LeaderboardLv.Parent = Leaderboard
local function UpdateLeaderstats()
LeaderboardWins.Value = Gold.Value
LeaderboardLv.Value = Level.Value
end
Level.Changed:Connect(UpdateLeaderstats)
Gold.Changed:Connect(UpdateLeaderstats)
Exp.Changed:Connect(function()
local plrStats = DataStore2("Stats", plr):GetTable(CreateDataTable())
if plr.PlayerStats.Exp.Value >= plr.PlayerStats.MaxExp.value then
plrStats.Level = plrStats.Level + 1
plrStats.Exp = 0
plrStats.MaxExp = plrStats.MaxExp + 50
DataStore2("Stats", plr):Set(plrStats)
end
end)
end)
Yes i have tested it on roblox studio AND on a published place, and i have no clue why this suddenly started appearing