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

My leveling up script (with EXP) is not working properly?

Asked by 7 years ago
Edited 7 years ago

I want to make a leveling up system and the EXP script won't work. The script is when you get to 50 EXP you level up. It adds 50 more EXP every level... This is what I have in workspace:


function onPlayerEntered(newPlayer) wait(.5) local stats = Instance.new("IntValue") stats.Name = "leaderstats" local cash = Instance.new("IntValue") cash.Name = "Level" cash.Value = 1 --This sets the Level every player starts with cash.Parent = stats stats.Parent = newPlayer local cash = Instance.new("IntValue") cash.Name = "EXP" cash.Value = 0 --This sets the amount of XP every player starts with cash.Parent = stats stats.Parent = newPlayer local cash = Instance.new("IntValue") cash.Name = "Money" cash.Value = 100 --This sets the amount of Money every player starts with cash.Parent = stats stats.Parent = newPlayer end game.Players.ChildAdded:connect(onPlayerEntered)

This is a separate script that I have in workspace:

function onPlayerEntered(newPlayer) --When a player enters
    L = newPlayer.stats.Level
    e = newPlayer.stats.EXP
    scr = script:clone() --Clones the script so you can give this to EVERYONE
    scr.Parent = newPlayer --Makes the cloned script's parent the newPlayer

    function checkXP() --name of the function
        if e.Value >= 50*L.Value then --if the EXP value is greater than or equal to 50 TIMES the player's level then. 

            L.Value = L.Value+ 1 --Increase a Level
            e.Value = 0 --Reset XP value to 0
        end --end the if statement
    end --end the function
    e.Changed:connect(checkXP) --conneciton for checkXP function
end --end the onPlayerEntered function
game.Players.ChildAdded:connect(onPlayerEntered) --connection for onPlayerEntered function

Please Help...

0
sorry it gliched ProgrammableGami 23 — 7y
0
Please close your entire code between the two tilde bars(~~~) so we can better help you! :D antonio6643 426 — 7y
0
Yes, above with what Antonio said, please format your code with a Code Block (The Lua button). Eqicness 255 — 7y
0
Sorry about that. ProgrammableGami 23 — 7y

1 answer

Log in to vote
0
Answered by
Anubizx 76
7 years ago

I really dont understand your code, so... here is my leveling script:

First, add this code in a localscript at StarterPack

local P = game.Players.LocalPlayer
local C = P.Character or P.CharacterAdded:wait()
local leaderstat = P:WaitForChild'leaderstat'
local EXP = leaderstat:WaitForChild'EXP'
local Level = leaderstat:WaitForChild'Level'

EXP.Changed:connect(function() if Level then
if EXP then if EXP.Value < 0 then EXP.Value = Level.Value * 60
if C then if Level then Level.Value = Level.Value + 1
end end end end end end)

You can change (Level.Value * 60), 60 = How much EXP will add at next level.

Ad

Answer this question