Trying to make badge get awarded after a player waits alone in a server for a hour

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? I want to make a badge that gets awarded when you wait alone (only you in server) in a server for a hour

  2. What is the issue? I’ve tried testing the script and it didnt seem to work, there were no errors in the output and i couldn’t find what was causing the script to not work.

  3. What solutions have you tried so far? I tried looking into the dev forum for solutions but i’ve found nothing related to my issue.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local Players = game:GetService("Players")
local AmountOfPlayers = #Players:GetPlayers()

Players.PlayerAdded:Connect(function(Player)
	AmountOfPlayers = AmountOfPlayers + 1
end)

Players.PlayerRemoving:Connect(function(Player)
	AmountOfPlayers = AmountOfPlayers - 1
end)

local timeWaited = 0

if AmountOfPlayers == 1 then
while true do
	task.wait(1)
		timeWaited = timeWaited + 1
		print("Added 1 Second to Time Waited")
	if AmountOfPlayers == 2 then
			timeWaited = 0
			print("Time has been reset.")
		break
	elseif timeWaited >= 10 and AmountOfPlayers == 1 then
			local BS = game:GetService("BadgeService")
			BS:AwardBadge(Players[1].UserId,2146555899)
			print("Badge has been awarded.")
		end
	end
	end

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

The script is prolly running before a player joins the server and thus it doesn’t get to the while loop. So instead try this:

local Players = game:GetService("Players")
local AmountOfPlayers = #Players:GetPlayers()

Players.PlayerAdded:Connect(function(Player)
	AmountOfPlayers = AmountOfPlayers + 1
end)

Players.PlayerRemoving:Connect(function(Player)
	AmountOfPlayers = AmountOfPlayers - 1
end)

local timeWaited = 0

while task.wait(1) do
	timeWaited += 1

	print("Added 1 Second to Time Waited")
	if AmountOfPlayers >= 2 then
	        timeWaited = 0
		print("Time has been reset.")
	elseif timeWaited >= 10 then
		local BS = game:GetService("BadgeService")
			BS:AwardBadge(Players[1].UserId,2146555899)
		print("Badge has been awarded.")
	end
end

P.S: This aint the best way to do this and I would have provided a beter method but typing code on mobile is easier said than done.

1 Like

Thank you for helping me! The script worked exactly how i wanted it to be! :smiley:
thank you so muchh

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.