A badge is given to the player from a crystal part with a touched event. When the player touches the crystal, they would receive a badge if they don't have it already or else it would print that the player already has the badge. The issues here is when i test it, it displays in the output that the humanoid is not detected when the player touches it. If there is something I am doing wrong, please let me know. Thank you!

local function onCrystalTouched(hit)
	if crystalTouched == false then
		crystalTouched = true
		
		local humanoid = hit.Parent:FindFirstChildOfClass("Humanoid")
		if humanoid then
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			
			if player then
				print("found player")
				if not BadgeService:UserHasBadgeAsync(player.UserId, badgeId) then 
					print("Player has been awarded the Hidden badge")
					BadgeService:AwardBadge(player.UserId, badgeId)
					wait(5)
					humanoid.Health = 0
					crystalTouched = false
				else
					print("player does have the badge already")
					crystalTouched = false
				end
			end
			
		else
			print("humanoid not found")
		end
		
		wait(5)
		crystalTouched = false
	end
end

crystal.Touched:Connect(onCrystalTouched)

3 comments

0

Have you tried something like “Touched:Connect”?

0

script.Parent.Touched:Connect(onCrystalTouched) You have to connect it to the correct event.

0

I do have it connected with the event, i just didn't write it up there. (I edited it with the event)