So I created a datastore script to save the level and xp, and after doing so the dictionary variables are unsaved. Here are the code and the error.
game.Players.PlayerAdded:Connect(function(p)
local e = script.lvg:Clone()
e.Parent = p.PlayerGui
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("lv")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(p.Name)
end)
if success then
e.Frame.xpv.Value = currentExperience["xp"]
e.Frame.lvv.Value = currentExperience["lv"]
end
end)
And
if p.Parent.Name=="Forest Goon" then
if cooldown==false then
cooldown = true
p.Parent.Humanoid.Health = p.Parent.Humanoid.Health-math.random(33,88)
local DataStoreService = game:GetService("DataStoreService")
local experienceStore = DataStoreService:GetDataStore("lv")
local success, currentExperience = pcall(function()
return experienceStore:GetAsync(p.Name)
end)
if success then
if currentExperience~=nil then
local newt = {
xp = 0,
lv = 0,
}
if currentExperience.xp+5>=currentExperience.lv*50 then
newt = {
xp = 0,
lv = currentExperience.lv+1,
}
else
newt = {
xp = currentExperience.xp+5,
lv = currentExperience.lv
}
end
experienceStore:SetAsync(game.Players[""..script.Parent.Parent.Parent.Name],newt)
local t = "xp"
local n = newt["xp"]
game.Players[""..script.Parent.Parent.Parent.Name].PlayerGui.lvg.Frame.RemoteEvent:FireClient(game.Players[""..script.Parent.Parent.Parent.Name],t,n)
local t = "lv"
local n = newt["lv"]
game.Players[""..script.Parent.Parent.Parent.Name].PlayerGui.lvg.Frame.RemoteEvent:FireClient(game.Players[""..script.Parent.Parent.Parent.Name],t,n)
else
local newt = {
xp = 5,
lv = 1,
}
experienceStore:SetAsync(game.Players[""..script.Parent.Parent.Parent.Name],newt)
local t = "xp"
local n = newt["xp"]
game.Players[""..script.Parent.Parent.Parent.Name].PlayerGui.lvg.Frame.RemoteEvent:FireClient(game.Players[""..script.Parent.Parent.Parent.Name],t,n)
local t = "lv"
local n = newt["lv"]
game.Players[""..script.Parent.Parent.Parent.Name].PlayerGui.lvg.Frame.RemoteEvent:FireClient(game.Players[""..script.Parent.Parent.Parent.Name],t,n)
end
end
wait(.1)
cooldown = false
end
end