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

Game Doesnt Kick Players And Gives Them Badges After All Values In PlayerGui Equal Something?

Asked by 2 years ago

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)

01local badgeservice = game:GetService("BadgeService")
02local id = 2142031533 --put badge id here
03 
04while 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
17end

1 answer

Log in to vote
1
Answered by 2 years ago
Edited 2 years ago

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.

01local badgeservice = game:GetService("BadgeService")
02local id = 2142031533 --put badge id here
03 
04while 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)
View all 23 lines...
0
i had to add playergui but it worked! JmoneyPlayzOfficial 49 — 2y
Ad

Answer this question