Please don’t use the Scripting Support category as a dump-and-run hub for broken code. Posting your entire code and saying it’s broken is not only improper use of the category but an inconvenience for those who are replying to your question. Please see the category guidelines for more information.
In spite of the above information, I’m going to help you out with your code. There’s only one major issue and that has to do with the fact that your loop is blocking the rest of the script from running.
Here are some bones to pick with your code:
There’s a lot of unnecessary whitespace. Get rid of those to help with the readability of your code.
Use clear variable names. Your stat value variable name is
mins yet the name of the actual data is
Dips. Seeing as your
Dips aren’t incremented every minute, this is useless to include.
In the case of working with features for certain users, you should work with their UserIds as opposed to their usernames. Usernames are change-bound.
- If you’re too lazy to fish out the UserId of a user, you can pass a username through Players.GetUserIdFromNameAsync. It will return the UserId associated with the username, regardless of whether or not it’s a player’s current username.
Don’t use a while loop here.
In terms of practice, while wait loops are not good. You also should not be having that loop inside of your PlayerAdded handler.
You shouldn’t be using a loop here at all. What you should be doing is hooking a function that detects when the value changes and award it from there.
Hold things in variables so you don’t have to repeat them. In your badge function, you pass the id three times. Instead, you can assign a variable to the id and pass the variable three times. This is just something for sanity and convention’s sake.
The badge function isn’t ever called, so it’ll never be awarded. You don’t need to check the legality or disabled properties of the badge either, realistically. Wrap the badge call in a pcall to catch errors received from attempting to award the badge.
Here is some code you can work with. You’ve already got code so I’m just rearranging it and applying new fixes; normally, I wouldn’t give you the code if you didn’t already have a proto down.
local Players = game:GetService("Players")
local BadgeService = game:GetService("BadgeService")
local BADGE_ID = 2124484177
-- player is easier to write out, so I changed the variable name
local function playerEntered(player)
-- Use a Folder, more appropriate
local stats = Instance.new("Folder")
stats.Name = "leaderstats"
local dips = Instance.new("IntValue")
dips.Name = "Dips" -- New IntValues have a default value of 0
-- Example of what I meant by use Players.GetUserIdFromNameAsync
if player.UserId == Players:GetUserIdFromNameAsync("EggService") or player.UserId == Players:GetUserIdFromNameAsync("BusinessUwU") then
dips.Value = 9999
-- In case Dips goes over 10000, give those players the badge too
if value >= 10000 then
-- Wrap the function call directly
pcall(BadgeService.AwardBadge, BadgeService, player.UserId, BADGE_ID)
dips.Parent = stats
stats.Parent = player
for _, player in pairs(Players:GetPlayers()) do
The only valid fix in your post is that the function wasn’t called. Nothing else needs to be replaced. PlayerAdded is simply the canonical function to use here; it’s a version of ChildAdded that only fires for players and follows different protocols.