Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why is my level system not working properly?

Asked by 6 years ago
Edited 6 years ago

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)
1
use Players.PlayerAdded, not ChildAdded Gey4Jesus69 2705 — 6y
0
ChildAdded works unless you put something in Players yourself clc02 553 — 6y

1 answer

Log in to vote
0
Answered by
clc02 553 Moderation Voter
6 years ago

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

Ad

Answer this question