Script is disregarding current leaderstat value made by another LocalScript

So basically, I have a continuous loop giving a player 25 exp points every 30 seconds. I have another LocalScript embedded in the StarterPlayerScripts that has a function that fires whenever a player chats, which gives them 5 exp points. The points given by the LocalScript add on to the true Current exp value and correctly show up on the GUI. However, whenever the loop script fires, it simply adds onto itself, disregarding the new value given by the LocalScript.

For example, say I get 25 exp points from the loop script, then I chat and get another 5 exp points, I will then have 30 exp points. But the second time the loop script fires, instead of giving me a total 55 exp points, it gives me only 50 exp points (sorry if that was a bit confusing).

TL;DR: It doesn’t seem to recognize the points given by the LocalScript.

Here’s the main script with the continuous loop, located in the ServerScriptService:

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local level = Instance.new("IntValue", leaderstats)
	level.Name = "Level"
	level.Value = 1

	local exp = Instance.new("IntValue", level)
	exp.Name = "Current"
	exp.Value = 0

	local maxExp = Instance.new("IntValue", level)
	maxExp.Name = "Max"
	maxExp.Value = 100

	-- continous loop

	function additionXP()
		player.leaderstats.Level.Current.Value = player.leaderstats.Level.Current.Value + 25
	end
	
	while true do
		wait(30)
		additionXP()
		print("XP given!")
		if exp.Value >= maxExp.Value then
			level.Value = level.Value + 1
			exp.Value = 0
			maxExp.Value = maxExp.Value + 100
		end
	end
end) 

Then here’s the LocalScript located in the StarterPlayerScripts:

local player = game:GetService("Players").LocalPlayer
local canChat = true
local coolDown = 10 

player.Chatted:Connect(function(message) 
	
	if canChat then
		canChat = false 

		coroutine.wrap(function() 
			wait(coolDown)
			canChat = true 
		end)()
		player.leaderstats.Level.Current.Value = player.leaderstats.Level.Current.Value + 5
	end
end)
2 Likes
player.leaderstats.Level.Current.Value = player.leaderstats.Level.Current.Value + 5

This property assignment won’t replicate to the server. You can read more about that here, note the exceptions heading.

In short, you can’t change leaderstats values from a LocalScript. Well you can, but the change only appears on the specific client that made the change.

With this script:

local player = game.Players.LocalPlayer
local leaderstats = player:WaitForChild("leaderstats")
while wait(1) do
	leaderstats.Cash.Value += 1
end

it will look like the palyer gets 1 cash every second. But if you inspect the IntValue object from a server context it will remain at 0. When testing in Studio you can change between a client and server context by clicking this button:

image