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?

2 comments
How much exp is required to get to Level 1, 2, 3, 4 and 5? That will help lots.
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.