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

How do I get my leveling script to legitimately update leaderstat values?

Asked by 3 years ago

I'm creating a part that gives you exp when stepped on. All of this is running in a server script within the part. The 'expVal' and 'levVal' are IntValues created by another script, stored in a folder found in Players.

part = script.Parent
debounce = true

part.Touched:Connect(function(active)
    local humanoid = active.Parent:FindFirstChild("Humanoid")
    local player = game.Players:GetPlayerFromCharacter(humanoid.Parent)

    local function grantExp(amount)
        local stat = player:FindFirstChild('stats')
        if not stat then return end
        local exp = stat:FindFirstChild('exp')
        if not exp then return end
        local level= stat:FindFirstChild('level')
        if not levelthen return end
        local expVal = exp.Value
        local levVal = level.Value


        expVal = expVal + amount
        print(player.Name..', has been given '..amount..' experience!')
        local expNeeded = math.floor(((levVal+1)*100)^(9/10))
        while expVal >= expNeeded do 
            expVal = expVal - expNeeded
            levVal += 1
            print(player.Name..', is now level '..levVal..'!')
            expNeeded = math.floor(((levVal+1)*100)^(9/10))
        end

    end

    if (humanoid ~= nil) and (debounce == true) then
        debounce = false
        grantExp(1000)
        wait(1) --debounce timer
        debounce = true
    end
end)

When the part is stepped on the code runs (with both values starting at 0) and outputs:

Player has been given 1000 experience!

Player is now level 1!

Player is now level 2!

Player is now level 3!

Player is now level 4!

Player is now level 5!

When the part is stepped on again it outputs the exact same thing. How do I get the script to actually update the values of the two variables, rather than just pretending to and repeating the process from 0 every time?

0
How much exp is required to get to Level 1, 2, 3, 4 and 5? That will help lots. dxrrevn 13 — 3y
0
The values themselves are fairly arbitrary. Currently I'm using a logarithmic scale given by the formula on line 26. Going from level 0 to 1 requires about 63 exp; going from level 9 to 10 requires about 500. The issue isn't the exp being given out, it's that the IntValues are not being updated when the script runs, so it always runs with them starting at 0. reshape 0 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

https://devforum.roblox.com/t/cannot-change-intvalue-with-script/431897/2

Found a solution to this completely asinine bug. Turns out my code was solid. Only change I made was removing lines 15 and 16:

local expVal = exp.Value
local levVal = level.Value

Anywhere where those to variable appeared afterwards we replaced with exp.Value or level.Value

Ad

Answer this question