How do I make a player award a badge by touching multiple parts?

Hi developers!
I’m trying to make a Badge awarded by touching a lot of parts but I still don’t figure out how to do that if you can help me to find a solution I will be thankful.
Example: “You need collect 10 coins for get the Badge”

2 Likes

You could add a NumberValue to the player, and if the player reaches x amount of touches, then it would award the badge.

Here’s some starter code. I didn’t test it so there’s a possibility it might be wrong:

game.Players.PlayerAdded:Connect(function(player)
	local value = Instance.new("NumberValue", player)
	value.Name = "PlayerTouches"
end)

function onTouched(part)
	if part.Parent ~= nil then
		local humanoid = part.Parent:FindFirstChild("Humanoid")
		if humanoid ~= nil then
			local player = game.Players:FindFirstChild(part.Parent.Name)
			if player ~= nil then
				player:FindFirstChild("PlayerTouches").Value = player.PlayerTouches.Value + 1
			end
		end
	end
end

script.Parent.Touched:connect(onTouched)
2 Likes

I haven’t thought-out about using NumberValue thanks :smile:

1 Like

I may be wrong but I think he meant IntValue.

3 Likes

Right. My bad, I forgot Bool is true/false. I meant IntValue or NumberValue.

You can use boolvalues but that would be extra steps… But since he wanted multiple parts touching for a badge, boolvalue would be a good approach.

Also, for multiple parts at once you can use GetTouchingParts, for multiple parts that aren’t touching the player at once you can create multiple debounces, when they are all true you can award the badge.

1 Like