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?
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