Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make it so when you collect alot of items u get awarded a badge?

So, i'm wondering how to make it, well you know in the title. Basically someone clicks a shell and the shell gets deleted so it acts like it got collected.

This is the click to delete script.

function onClicked()
script.Parent:remove()
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)

Below is the badge script. How can i make it award at 10 items?

print("Badge Awarder Loaded. BadgeID: " .. script.Parent.BadgeID.Value)



-- ROBLOX scripter hackers, see what you can do with this:
-- game:GetService("BadgeService"):UserHasBadge(userid, badgeid)


function OnTouch(part)
	if (part.Parent:FindFirstChild("Humanoid") ~= nil) then
		local p = game.Players:GetPlayerFromCharacter(part.Parent)
		if (p ~= nil) then
			print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. p.userId)
			local b = game:GetService("BadgeService")
			b:AwardBadge(p.userId, script.Parent.BadgeID.Value)
		end
	end
end

script.Parent.Touched:connect(OnTouch)

Also i just signed up.

9 comments

0

Create an Int variable, when the item is "deleted" or "collected" add 1 to it, in the badge script check when that variable changes, and once its at 10 award badge.

0

Could you post an example?

0

First, you have this badge in a touched script, does it need to be?

0

Well you click the shells and it disappears and that stands out as you collected it.

0

Im gonna take that as a no.

0

Could you like post something in answers or idk, Btw the shells are called "ShotgunShells"

0

There seems to be a red underline at the onClicked, line 4.

0

Well it seems alright now. local db = false local Collected = "Collected" -- you'll need to add in an IntValue somewhere, if you have a leaderstats script you can use that to add the "Collected" value to the player then reference it here function onClicked() if not db then -- I added a DB but may not be needed, but just in case. db = true Collected.Value = Collected.Value + 1

0

Doesn't seem to be working, i'm confused with the Collected =.

1 answer

Alright so im doing this in the editor but this should work ok. When you click the shell or whatever it adds 1 to the int value, wherever that ends up. Once you have 10 the badge script will award it once, then once its awarded the nobadge variable should stop it from continuing to try to.

"Click to delete" script.

local db = false
local Collected = -- you'll need to add in an IntValue somewhere, if you have a leaderstats script you can use that to add the "Collected" value to the player then reference it here

function onClicked()
	if not db then -- I added a DB but may not be needed, but just in case. 
		db = true
		Collected.Value = Collected.Value + 1 -- we add 1 to value
		script.Parent:remove()
		wait(.25)
		db = false
	end
end

script.Parent.ClickDetector.MouseClick:Connect(onClicked)

Badge script

local Collected = -- again reference that int value we're making
local nobadge = true

Collected.Changed:Connect(function(player)
	if Collected.Value >= 10 and nobadge then 
		nobadge = false
		print("Awarding BadgeID: " ..script.Parent.BadgeID.Value .. " to UserID: " .. player.userId)
		local b = game:GetService("BadgeService")
		b:AwardBadge(player.userId, script.Parent.BadgeID.Value)
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.