I am working on a Pokemon game using Pokemon Evolutions made by dragon115454 as the base game. Everything went well so far, but after a certain update (I don't know which) people started complaining about their levels not being saved. Although, I didn't edit anything in the save script, so it might be the "stats" script that is the problem.
Saving script:
game.Players.PlayerRemoving:connect(function(p)
if p:findFirstChild("stats") then
p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.stats)
end
end)
game.Players.PlayerAdded:connect(function(p)
for k = 1, 60, 0.03 do
wait()
if p:findFirstChild("stats") and p.DataReady then break end
end
local Loaded = nil
if p:findFirstChild("stats") and pcall(function() Loaded = p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId)) end) then
for j, v in pairs(Loaded:GetChildren()) do
pcall(function() p.stats[v.Name].Value = v.Value end)
end
end
end)
Stats script:
function onXPChanged(player, XP, level)
if XP.Value>=level.Value * 10 then
XP.Value = XP.Value - level.Value * 10
level.Value = level.Value + 1
end
end
function onLevelUp(player, XP, level)
local m = Instance.new("Hint")
m.Parent = game.Workspace
m.Text = player.Name .. " has gained a level."
wait(3)
m.Parent = nil
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue")
stats.Name = "stats"
local xp = Instance.new("IntValue")
xp.Name = "XP"
xp.Value = 0
local level = Instance.new("IntValue")
level.Name = "Level"
level.Value = 1
local c = Instance.new("IntValue")
c.Name = "Cash"
c.Value = 0
local f = Instance.new("IntValue")
f.Name = "FS"
f.Value = 15
local t = Instance.new("IntValue")
t.Name = "Type"
t.Value = 0
local t2 = Instance.new("IntValue")
t2.Name = "Type2"
t2.Value = 0
local p = Instance.new("IntValue")
p.Name = "Potion"
p.Value = 3
local ob = Instance.new("IntValue")
ob.Name = "OranBerry"
ob.Value = 5
local ThunderStone = Instance.new("IntValue")
ThunderStone.Name = "ThunderStone"
ThunderStone.Value = 0
local FireStone = Instance.new("IntValue")
FireStone.Name = "FireStone"
FireStone.Value = 0
local WaterStone = Instance.new("IntValue")
WaterStone.Name = "WaterStone"
WaterStone.Value = 0
local LeafStone = Instance.new("IntValue")
LeafStone.Name = "LeafStone"
LeafStone.Value = 0
local e1 = Instance.new("IntValue")
e1.Name = "Event1"
e1.Value = 0
local pidgey = Instance.new("IntValue")
pidgey.Name = "Pidgey"
pidgey.Value = 0
local caterpie = Instance.new("IntValue")
caterpie.Name = "Caterpie"
caterpie.Value = 0
local sbulbasaur = Instance.new("IntValue")
sbulbasaur.Name = "SBulbasaur"
sbulbasaur.Value = 0
local mew = Instance.new("IntValue")
mew.Name = "Mew"
mew.Value = 0
local r = Instance.new("IntValue")
r.Name = "Rock"
r.Value = 0
local rc = Instance.new("IntValue")
rc.Name = "RareCandy"
rc.Value = 0
xp.Parent = stats
level.Parent = stats
c.Parent = stats
f.Parent = stats
t.Parent = stats
t2.Parent = stats
p.Parent = stats
ThunderStone.Parent = stats
e1.Parent = stats
pidgey.Parent = stats
caterpie.Parent = stats
ob.Parent = stats
FireStone.Parent = stats
WaterStone.Parent = stats
LeafStone.Parent = stats
sbulbasaur.Parent = stats
mew.Parent = stats
r.Parent = stats
rc.Parent = stats
stats.Parent = newPlayer
xp.Changed:connect(function() onXPChanged(newPlayer, xp, level) end)
level.Changed:connect(function() onLevelUp(newPlayer, xp, level) end)
newPlayer.Changed:connect(function (property)
if (property == "Character") then
onPlayerRespawned(newPlayer)
end
end)
end
game.Players.ChildAdded:connect(onPlayerEntered)
I added a manually save/load script and that works well, so I have no flippin' idea why the old one suddenly doesn't work anymore.
My place: http://www.roblox.com/games/50269531/Pokemon-Advanced-Alpha
I can provide more informations if needed. Thank you for reading! :)
