I have a level up script which results in an error at the end I dont know why since I keep removing, adding brackets and adding on more ends but it doesn’t seem to work at all?
This is the script :
while task.wait() do
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV <=10 then
if EXP.Value >=LV.Value * LV.Value * 100 + 400 then
LV.Value = ((EXP.Value -400 )/100)^.5
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value >10 and LV.Value <=20 then
if EXP.Value >=LV.Value * LV.Value * 150 + 400 then
LV.Value = ((EXP.Value -400 )/150)^.5
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value >20 and LV.Value <30 then
if EXP.Value >=LV.Value * LV.Value * 200 + 400 then
LV.Value = ((EXP.Value -400 )/200)^.5
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value >= 30 and LV.Value <= 50 then
if EXP.Value >= (LV.Value^3 * 10) + 400 then
LV.Value = LV.Value + 1
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value > 50 and EXP.Parent.BeatD7.Value == 1 then
if EXP.Value >= LV.Value^3.6 then
LV.Value = EXP.Value^(1/3.6)
end
end
end
end
end
I dont know why it doesnt work its only the last line I’ve tried multiple different iterations of ending but still doesn’t seem to work help would be appreciated thank you!
while task.wait() do
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV <=10 then
if EXP.Value >=LV.Value * LV.Value * 100 + 400 then
LV.Value = ((EXP.Value -400 )/100)^.5
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value >10 and LV.Value <=20 then
if EXP.Value >=LV.Value * LV.Value * 150 + 400 then
LV.Value = ((EXP.Value -400 )/150)^.5
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value >20 and LV.Value <30 then
if EXP.Value >=LV.Value * LV.Value * 200 + 400 then
LV.Value = ((EXP.Value -400 )/200)^.5
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value >= 30 and LV.Value <= 50 then
if EXP.Value >= (LV.Value^3 * 10) + 400 then
LV.Value = LV.Value + 1
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:FindFirstChild("leaderstats")
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV.Value > 50 and EXP.Parent.BeatD7.Value == 1 then
if EXP.Value >= LV.Value^3.6 then
LV.Value = EXP.Value^(1/3.6)
end
end
end)
end
I chucked it into studio, formatted it, and corrected some of the syntax issues
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats", 10)
local EXP = leaderstats.EXP
local LV = leaderstats.LV
if LV <=10 then
if EXP.Value >=LV.Value * LV.Value * 100 + 400 then
LV.Value = ((EXP.Value -400 )/100)^.5
end
elseif LV.Value > 10 and LV.Value <=20 then
if EXP.Value >= LV.Value * LV.Value * 150 + 400 then
LV.Value = ((EXP.Value -400 )/150)^.5
end
elseif LV.Value > 20 and LV.Value <30 then
if EXP.Value >=LV.Value * LV.Value * 200 + 400 then
LV.Value = ((EXP.Value -400 )/200)^.5
end
elseif LV.Value >= 30 and LV.Value <= 50 then
if EXP.Value >= (LV.Value^3 * 10) + 400 then
LV.Value = LV.Value + 1
end
elseif LV.Value > 50 and EXP.Parent.BeatD7.Value == 1 then
if EXP.Value >= LV.Value^3.6 then
LV.Value = EXP.Value^(1/3.6)
end
end
end)
Attempt to index nil with EXP means that you are trying to index the EXP instance which doesnt exist (nil); adding the :WaitForChild() ensures that the EXP instance loads in the folder before returning it.
And as @Kurtziru said adding the :WaitForChild() did fix this error
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local EXP = leaderstats.EXP.Value
local LV = leaderstats.LV.Value
while task.wait() do
if LV <=10 then
if EXP >=LV * LV * 100 + 400 then
LV = ((EXP -400 )/100)^.5
end
elseif LV > 10 and LV <=20 then
if EXP >= LV * LV * 150 + 400 then
LV = ((EXP -400 )/150)^.5
end
elseif LV > 20 and LV <30 then
if EXP >=LV * LV * 200 + 400 then
LV = ((EXP -400 )/200)^.5
end
elseif LV >= 30 and LV <= 50 then
if EXP >= (LV^3 * 10) + 400 then
LV = LV + 1
end
elseif LV > 50 and LV <= 50 then
if EXP >= LV^3.6 then
LV = EXP^(1/3.6)
end
end
end
end)
I put a while wait do and it still doesn’t do anything? Do you know why possibly
While loops are probably not the best solution here, but if you do wish to use them:
Put
local EXP = leaderstats.EXP.Value
local LV = leaderstats.LV.Value
INSIDE the loop:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local EXP = leaderstats.EXP.Value
local LV = leaderstats.LV.Value
while task.wait() do
if LV <=10 then
if EXP >=LV * LV * 100 + 400 then
LV = ((EXP -400 )/100)^.5
end
elseif LV > 10 and LV <=20 then
if EXP >= LV * LV * 150 + 400 then
LV = ((EXP -400 )/150)^.5
end
elseif LV > 20 and LV <30 then
if EXP >=LV * LV * 200 + 400 then
LV = ((EXP -400 )/200)^.5
end
elseif LV >= 30 and LV <= 50 then
if EXP >= (LV^3 * 10) + 400 then
LV = LV + 1
end
elseif LV > 50 and LV <= 50 then
if EXP >= LV^3.6 then
LV = EXP^(1/3.6)
end
end
end
end)
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(player)
local leaderstats = player:WaitForChild("leaderstats")
local EXP = leaderstats.EXP.Value
local LV = leaderstats.LV.Value
leaderstats.EXP:GetPropertyChangedSignal("Value"):Connect(function()
if LV <=10 then
if EXP >=LV * LV * 100 + 400 then
LV = ((EXP -400 )/100)^.5
end
elseif LV > 10 and LV <=20 then
if EXP >= LV * LV * 150 + 400 then
LV = ((EXP -400 )/150)^.5
end
elseif LV > 20 and LV <30 then
if EXP >=LV * LV * 200 + 400 then
LV = ((EXP -400 )/200)^.5
end
elseif LV >= 30 and LV <= 50 then
if EXP >= (LV^3 * 10) + 400 then
LV = LV + 1
end
elseif LV > 50 and LV <= 50 then
if EXP >= LV^3.6 then
LV = EXP^(1/3.6)
end
end
end
end)