I want to make a timer that will start if you go through a portal, and if you survive for ten minutes it gives you a badge, but it is not working. no errors in the output, nothing.
this is the script:
counter = 600
local playerService = game:GetService("Players")
script.Parent.Touched:Connect(function(part)
if part.Parent:FindFirstChild("Humanoid") then
part.Parent.HumanoidRootPart.CFrame = game.Workspace.CEP2.Telepad.CFrame
local player = playerService:GetPlayerFromCharacter(part.Parent)
local humanoid = part.Parent:FindFirstChild("Humanoid")
local gui = Instance.new("ScreenGui")
gui.Parent = player.PlayerGui
local text = Instance.new("TextLabel")
text.Parent = gui
text.Text = 600
while true do
wait(1)
counter = counter - 1
text.Text = counter
end
while true do
if counter == 0 then
print("Badge given or already given before.")
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local Part = script.Parent
local IDToAward = 2129501457
local debounce = true
if not player or BadgeService:UserHasBadgeAsync(player.UserId, IDToAward) or not debounce then
return
end
BadgeService:AwardBadge(player.UserId, IDToAward)
break
end
end
local function died()
gui:Destroy()
end
humanoid.Died:Connect(died)
end
end)
I have tried remaking the code many times, I looked on YouTube and DevForum for anything similar to this but can not find anything.
If you know what is wrong with my code, please let me know.
Where does it stop working? Like does the UI indeed show up and start counting down? Or does the UI show up but doesn’t count down? Or does both the UI and Counter work, but badge doesn’t get awarded?
The print that says you got the badge or already have it does not print, meaning it is the function above that does not actually called called somehow. the ui does not even show up.