Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my level system not working properly?

I'm pretty new to scripting so sorry if it's something that should be obvious. I am trying to make a level system in which the longer players play the higher the level they become. The only issue is that if there are multiple players in the server at once it counts everyone's XP and when the whole server reaches the lowest XP needed for a player to level up it levels up that player.


minutes = 0
xpRate = 5 
function onPlayerEntered(newPlayer)
	wait(.5)
	local stats = Instance.new("IntValue")
	stats.Name = "leaderstats"

	local score = Instance.new("IntValue")
	
	score.Name = "Money"
	score.Value = 0

	score.Parent = stats	
	stats.Parent = newPlayer
	
	local level = Instance.new("IntValue")
	
	level.Name = "Level"
	level.Value = 1

	level.Parent = stats	
	stats.Parent = newPlayer
	
	local XP = Instance.new("IntValue")
	
	XP.Name = "XP"
	XP.Value = 0

	XP.Parent = stats	
	stats.Parent = newPlayer
	
	while minutes <= xpRate do
		wait(60)
		minutes = minutes + 1
		score.Value = score.Value + 25
		XP.Value = XP.Value + 5
	
	if minutes == xpRate then
		minutes = 0
		xpRate = xpRate + 2
		XP.Value = 0
		level.Value = level.Value + 1
	end
	end
end

game.Players.ChildAdded:connect(onPlayerEntered)

2 comments

1

use Players.PlayerAdded, not ChildAdded

0

ChildAdded works unless you put something in Players yourself

1 answer

✓ Accepted answer

Rename minutes and xpRate to something like gminutes and gxpRate, then after line 3 put

local minutes = gminutes
local xpRate = gxpRate

The problem is minutes and xpRate are out of scope of the function, changing it for one player changes it for everyone

This discussion is preserved as it was. New answers, comments, and votes are closed.