Touch to start survival timer

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.

also sorry for making so many posts recently

Hello!

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.

I see, so it really leads up to the the UI and the counter.

Does the UI actually show up on the screen and start counting down?

no, the ui does not show up at all. The only thing it does is teleport me.

1 Like

Instead of Getting PlayerService,

Try game.Players

I believe it does show up maybe set the placement on the text label and make the text size bigger.

1 Like

I will try this and what matt suggested

That too, never saw any lines that change the properties of the ui!

Good spot.

And it looks like you should use a debounce it created 4 gui’s.

unfortunately it still is not showing up.

1 Like

right, I will add that
good idea

Oh alright, did DLBs idea work?

I was talking about both of them

when i run it this is what i see.
Dlbsp1983's Place Number_ 18 - Roblox Studio 11_19_2022 3_34_22 PM (2)

1 Like

Have you considered making the UI beforehand, then having it parented to the playerUI when touch event goes?

(sorry I didn’t mention this sooner, mb)

I made the text scaled, and I checked the properties in test and it seems to have the text changing and it does exist it just will not show up.

I could do that, I will try it now.

2 Likes

ok, so it does how up now, and it does count down, but it still will not give the badge.

1 Like

Alr, that’s good to hear,

Try to move this into this