Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Player level up script isnt working? No errors either?

Asked by 6 years ago

I have a very simple level up script and when a players EXP value hits a certain point its supposed to add a point to the level script but it doesnt? Nor does it error.

Does anyone know why?

Heres the script, its very simple just if a int value reaches a certain point then it level you up, very veryyy simple

local ReplicatedStorage = game:GetService("ReplicatedStorage")

game.Players.PlayerAdded:connect(function(Player)
    local ExperiencePoints = ReplicatedStorage.DataFile:WaitForChild(Player.Name).ExperiencePoints
    local PlayerLevel = ReplicatedStorage.DataFile:WaitForChild(Player.Name).PlayerLevel
    while true do
        if ExperiencePoints.Value == "2500" then
            print("Level Up")
            PlayerLevel.Value = PlayerLevel.Value + 1
        end
        wait()
    end
end)

Its a script inside ServerScriptService incase you are wondering, anyhow have a good day and Merry Christmas!

2 answers

Log in to vote
1
Answered by 6 years ago

this error is simple, you put the numbers in quotation marks, this makes the script check for a string value when it will never find one, that's why there is no error.

Ad
Log in to vote
0
Answered by 6 years ago

I have a similar script, but it's included with my Leaderstats portion of my DataStore, I'd recommend doing the same. :) Here's how I do it in my script, maybe this will help you.

local required = (PlayerLevel.Value*100) -- change the 100 to whatever factor you want each level to increase by, for example level 1 = 100 XP, level 2 = 200 XP, level 3 = 300 XP etc.

    ExperiencePoints.Changed:Connect(function()
        if ExperiencePoints.Value >= required then
            PlayerLevel.Value=PlayerLevel.Value+1
            ExperiencePoints.Value = ExperiencePoints.Value-required
        end
    end)

Answer this question