Hello there, im making a script thats supposed to check every players specific values in playergui, if all of them are correct / working. it gives all the players a badge and kicks them. but for some reason the script doesn't work, I'm guessing its the script checking all the values but i have no idea
Script (The Run Context Is Server)
01 | local badgeservice = game:GetService( "BadgeService" ) |
02 | local id = 2142031533 --put badge id here |
03 |
04 | while task.wait() do |
05 | for _, plr in ipairs (game:GetService( 'Players' ):GetChildren()) do |
06 | if plr.PlayerTasks.Frame.music.Value.Value > = 250 |
07 | and plr.PlayerTasks.Frame.cook.Value.Value > = 4 |
08 | and plr.PlayerTasks.Frame.download.Value.Value > = 100 |
09 | and plr.PlayerTasks.Frame.upload.Value.Value > = 100 |
10 | and plr.PlayerTasks.Frame.tap.Value.Value > = 1 |
11 | and plr.PlayerTasks.Frame.tv.Value.Value > = 85 then |
12 | local plrid = plr.UserID |
13 | badgeservice:AwardBadge(plrid,id) |
14 | plr:Kick( "You Won The Game!!!" ) |
15 | end |
16 | end |
17 | end |
It's probably because either some of the players hasn't fully loaded yet, there are no players in the server, or both. What you can do is wrap Lines 6-14 in pcall()
to avoid errors.
Also in Line 12, the D in UserID should be lowercase, so it should be UserId, otherwise it will error.
01 | local badgeservice = game:GetService( "BadgeService" ) |
02 | local id = 2142031533 --put badge id here |
03 |
04 | while true do |
05 | for _, plr in ipairs (game:GetService( 'Players' ):GetChildren()) do |
06 | task.spawn( function () |
07 | pcall ( function () |
08 | if plr.PlayerTasks.Frame.music.Value.Value > = 250 |
09 | and plr.PlayerTasks.Frame.cook.Value.Value > = 4 |
10 | and plr.PlayerTasks.Frame.download.Value.Value > = 100 |
11 | and plr.PlayerTasks.Frame.upload.Value.Value > = 100 |
12 | and plr.PlayerTasks.Frame.tap.Value.Value > = 1 |
13 | and plr.PlayerTasks.Frame.tv.Value.Value > = 85 then |
14 | local plrid = plr.UserId |
15 | pcall (badgeservice.AwardBadge, badgeservice, plrid, id) |