Ad
Log in to vote
0

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

Asked by 13 days 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)

local badgeservice = game:GetService("BadgeService")
local id = 2142031533 --put badge id here

while task.wait() do
    for _, plr in ipairs(game:GetService('Players'):GetChildren()) do
        if plr.PlayerTasks.Frame.music.Value.Value >= 250
            and plr.PlayerTasks.Frame.cook.Value.Value >= 4 
            and plr.PlayerTasks.Frame.download.Value.Value >= 100
            and plr.PlayerTasks.Frame.upload.Value.Value >= 100
            and plr.PlayerTasks.Frame.tap.Value.Value >= 1
            and plr.PlayerTasks.Frame.tv.Value.Value >= 85 then
            local plrid = plr.UserID
            badgeservice:AwardBadge(plrid,id)
            plr:Kick("You Won The Game!!!")
        end
    end
end

1 answer

Log in to vote
1
Answered by 13 days ago
Edited 13 days 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.

local badgeservice = game:GetService("BadgeService")
local id = 2142031533 --put badge id here

while true do
    for _, plr in ipairs(game:GetService('Players'):GetChildren()) do
        task.spawn(function()
            pcall(function()
                if plr.PlayerTasks.Frame.music.Value.Value >= 250
                and plr.PlayerTasks.Frame.cook.Value.Value >= 4 
                and plr.PlayerTasks.Frame.download.Value.Value >= 100
                and plr.PlayerTasks.Frame.upload.Value.Value >= 100
                and plr.PlayerTasks.Frame.tap.Value.Value >= 1
                and plr.PlayerTasks.Frame.tv.Value.Value >= 85 then
                    local plrid = plr.UserId
                    pcall(badgeservice.AwardBadge, badgeservice, plrid, id)
                    plr:Kick("You Won The Game!!!")
                end
            end)
        end)
    end

    task.wait()
end
0
i had to add playergui but it worked! JmoneyPlayzOfficial 49 — 13d
Ad

Answer this question