I’ve researched how a value becomes nan and its if it becomes equal to 0/0.
The problem is, I have done nothing with my level value and it is profileservice value. I made some changes before to make a leveling system which I previously failed in but I am back to fix it.
I don’t want to make an if statement setting the players level to 1 to fix nan just because it will appear as nan in leveling gui for 1 round.
if level == 0/0 then
PlayerData:Set(player,"Level",1)
end
local function InPlayers(signal,par1,par2)
if signal == "Gain" then
local xp = par2:GetAttribute("RoundExperience")
par2:SetAttribute("RoundExperience",xp + par1)
return
end
for _,player in Players:GetPlayers() do
if signal == "Start" then
player:SetAttribute("RoundExperience",0)
elseif signal == "Receive" then
local experience = PlayerData:Get(player,"Experience")
local level = PlayerData:Get(player,"Level")
local progress = experience / (300 * level)
local new
if level == 0/0 then
PlayerData:Set(player,"Level",1)
end
if progress >= 1 then
new = math.abs(progress - level)
PlayerData:Set(player,"Level",level + 1)
PlayerData:Set(player,"Experience",progress)
end
print(experience,level,progress)
Remotes.ToClient:FireClient(player,"LoadXP",experience,level,new)
player:SetAttribute("Experience",nil)
end
end
end
This is the function I am using for my leveling system on the server.
Remotes.ToClient.OnClientEvent:Connect(function(signal,experience,level,progress)
if signal == "LoadXP" then
task.spawn(function()
LevelGui.Enabled = true
task.wait(5)
if LevelGui.Enabled then
LevelLabel.Text = ""
ExperienceLabel.Text = ""
Experience.Size = UDim2.fromScale(0,1)
LevelGui.Enabled = false
end
end)
LevelLabel.Text = "Level: " .. tostring(level)
ExperienceLabel.Text = "+"..tostring(experience).. " Experience!"
if experience > 0 then
TweenService:Create(Experience,TweenInfo.new(0.75,Enum.EasingStyle.Sine,Enum.EasingDirection.Out),{Size = UDim2.fromScale(progress,1)}):Play()
end
end
end)
This is the code handling the gui on the client.
I’m using a certain formula to track progress which is (experience / (300 * level)) but it hasn’t shown to work for me. I tried using temporary experience which would still save but be reset after you change a level(I was making players have permanent experience).