Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

1 comment

0

i had to add playergui but it worked!

This discussion is preserved as it was. New answers, comments, and votes are closed.