when you kill a mob in the rpg, it gives 5 gold and 5 xp but no matter how many times you kill something or how much xp and gold you get, it will not go past 10. please help here is the script

local datastore = game:GetService("DataStoreService"):GetDataStore("MyRPGDataStore") --Call "GameStore" whatever you like


game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("IntValue")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local xd = Instance.new("IntConstrainedValue")
	xd.Name = "Level"
	xd.Parent = leaderstats
	xd.Value = 1
	xd.MaxValue = workspace:FindFirstChild("GameSettings").MaxLevel.Value
	xd.MinValue = 0
	
	local qe = Instance.new("IntConstrainedValue")
	qe.Name = "EXP"
	qe.Parent = leaderstats
	qe.Value = 0
	xd.MaxValue = workspace:FindFirstChild("GameSettings").MaxEXP.Value
	xd.MinValue = 0
	
	local ss = Instance.new("IntConstrainedValue")
	ss.Name = "Gold"
	ss.Parent = leaderstats
	ss.Value = 0
	xd.MaxValue = workspace:FindFirstChild("GameSettings").MaxGold.Value
	xd.MinValue = 0
	
	local key = "user-" .. player.userId
	
	local storeditems = datastore:GetAsync(key)
	if storeditems then
		xd.Value = storeditems[1]
		qe.Value = storeditems[2]
		ss.Value = storeditems[3]
	else
		local items = {xd.Value, qe.Value, ss.Value}
		datastore:SetAsync(key, items)
	end
	
	while wait(120) do
		local stats = player:FindFirstChild("leaderstats")
		local aitems = {stats.Level.Value, stats.EXP.Value, stats.Gold.Value}
		local key = "user-" .. player.userId
	datastore:SetAsync(key, aitems)
	end
end)

game.Players.PlayerRemoving:connect(function(player)
	local stats = player:FindFirstChild("leaderstats")
	local items = {stats.Level.Value, stats.EXP.Value, stats.Gold.Value}
	local key = "user-" .. player.userId
	datastore:SetAsync(key, items)
end)

3 comments

1

Show us the code that awards gold & exp, this code is fine.

0

I used to have the same problem, Try redoing the order you put the Xp's Values in, Example: Instead of Value,MaxValue,MinValue try MaxValue,MinValue,Value This might not work but it's worth a shot :/

0

leaderstats is supposed to be a model, not an IntValue.