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.
01 | local badgeservice = game:GetService( "BadgeService" ) |
02 | local id = ( 2127329720 ) |
03 | script.Parent.Touched:Connect( function (hit) |
04 |
05 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
06 |
07 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
08 | badgeservice:AwardBadge(plr.UserId, id) |
09 | end |
10 | end ) |
11 |
12 | local mps = game:GetService( "BadgeService" ) |
13 |
14 | script.Parent.Touched:connect( function (plr) |
15 | local player = game.Players.LocalPlayer |
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:
01 | script.Parent.Touched:connect( function (plr) |
02 | local player = game.Players.LocalPlayer |
03 | script.Parent.Touched:Connect( function (hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | if player.Backpack:FindFirstChild( "TeddyBloxpin" ) then |
06 | print ( "Player already has TeddyBloxpin." ) |
07 | else |
08 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
09 | badgeservice:AwardBadge(plr.UserId, id) |
10 | game.ServerStorage.TeddyBloxpin:Clone().Parent = player.Backpack |
11 | game.ServerStorage.TeddyBloxpin:Clone().Parent = player.StarterGear |
12 | end |
13 | end |
14 | end ) |
15 | end ) |
Edit (Adding a cooldown timer instead):
01 | local debounce = true |
02 | local debouncetimer = 5 -- set this to how many seconds you want |
03 |
04 | script.Parent.Touched:connect( function (plr) |
05 | local player = game.Players.LocalPlayer |
06 | script.Parent.Touched:Connect( function (hit) |
07 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
08 | if debounce then |
09 | debounce = false |
10 | local plr = game.Players:GetPlayerFromCharacter(hit.Parent) |
11 | badgeservice:AwardBadge(plr.UserId, id) |
12 | game.ServerStorage.TeddyBloxpin:Clone().Parent = player.Backpack |
13 | game.ServerStorage.TeddyBloxpin:Clone().Parent = player.StarterGear |
14 | task.wait(debouncetimer) |
15 | debounce = true |
16 | end |
17 | end |
18 | end ) |
19 | end ) |
You could simply fire a Client RemoteEvent that either disables or destroy the script