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

wont level up? (line8 is error) Your title should be specific! Describe your

Asked by 2 years ago
game.Players.PlayerAdded:Connect(function(plr)
    plr:WaitForChild("stats")
    plr:WaitForChild("leaderstats")
    plr.stats:WaitForChild("exp")
    plr.leaderstats:WaitForChild("level")
    local l = plr.leaderstats.level
    local e = plr.stats.exp
    while true do
    if e.Value >= 50 then
            l.Value = l.Value +1
            wait(1)
        end
        end
end)

it wont make me level up when correct exp reached help?

0
You're not getting the player correctly yayaheyman 90 — 2y

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

Here is the fix for what you want using a text button:

-- Normal script:

script.Parent.LevelUp.OnServerEvent:Connect(function() -- Im using a remote even btw
    local plr = script.Parent.Parent.Parent
    if plr.exp.Value >= 50  then
        plr.leaderstats.Level.Value = plr.leaderstats.Level.Value + 1
        plr.exp.Value = plr.exp.Value - 50
    elseif plr.exp.Value < 50  then
        -- do nothing
    end
end)

-- Local script to fire upon clicking:

script.Parent.MouseButton1Click:Connect(function()
    script.Parent.Parent.LevelUp:FireServer()
end)

The problem with your script is

1: you're not getting the player correctly.

2: "stats" is a reserved word, meaning the server thinks it's something else.

my suggestions:

1: get the player through "script.parent" method

2: make the exp's parent the player not a folder.

Ad

Answer this question