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

How to only give one gear on touch and not a million?

I have a badge that gives the player a teddy bloxpin gear, but it gives them a million of them, I want it to give them 1.

local badgeservice = game:GetService("BadgeService")
local id = (2127329720)
script.Parent.Touched:Connect(function(hit)

	if hit.Parent:FindFirstChild("Humanoid") then

		local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
		badgeservice:AwardBadge(plr.UserId, id)
	end
end)

local mps = game:GetService("BadgeService")

script.Parent.Touched:connect(function(plr)
	local player = game.Players.LocalPlayer
	script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			badgeservice:AwardBadge(plr.UserId, id) 
			game.ServerStorage.TeddyBloxpin:Clone().Parent = player.Backpack
			game.ServerStorage.TeddyBloxpin:Clone().Parent = player.StarterGear
		end
	end)
end)

1 comment

0

Use something called debounce

2 answers

✓ Accepted answer

You could try finding that item inside their backpack, and if they already have it, then don't give it to them again. Maybe something like this:

script.Parent.Touched:connect(function(plr)
	local player = game.Players.LocalPlayer
	script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if player.Backpack:FindFirstChild("TeddyBloxpin") then
				print("Player already has TeddyBloxpin.")
			else
				local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
				badgeservice:AwardBadge(plr.UserId, id) 
				game.ServerStorage.TeddyBloxpin:Clone().Parent = player.Backpack
				game.ServerStorage.TeddyBloxpin:Clone().Parent = player.StarterGear
			end
		end
	end)
end)

Edit (Adding a cooldown timer instead):

local debounce = true
local debouncetimer = 5 -- set this to how many seconds you want

script.Parent.Touched:connect(function(plr)
	local player = game.Players.LocalPlayer
	script.Parent.Touched:Connect(function(hit)
		if hit.Parent:FindFirstChild("Humanoid") then
			if debounce then
				debounce = false
				local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
				badgeservice:AwardBadge(plr.UserId, id) 
				game.ServerStorage.TeddyBloxpin:Clone().Parent = player.Backpack
				game.ServerStorage.TeddyBloxpin:Clone().Parent = player.StarterGear
				task.wait(debouncetimer)
				debounce = true
			end
		end
	end)
end)

5 comments

0

It didn't work, there were no errors, but it didn't give me any teddies.

0

Then you could try adding a cooldown timer, it will mean they can get multiple, but it won't give a million at once.

0

I also edited the first script if you want it to only give one. Tell me if neither works.

0

I get this error and am given no gear: Workspace.Model.Model.SecretRoom.Part.Script:25: attempt to index nil with 'Backpack'

0

Nvm I fixed it

You could simply fire a Client RemoteEvent that either disables or destroy the script

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