Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 2 years ago

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.

01local badgeservice = game:GetService("BadgeService")
02local id = (2127329720)
03script.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
10end)
11 
12local mps = game:GetService("BadgeService")
13 
14script.Parent.Touched:connect(function(plr)
15    local player = game.Players.LocalPlayer
View all 24 lines...
0
Use something called debounce asmetics 26 — 2y

2 answers

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

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:

01script.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)
15end)

Edit (Adding a cooldown timer instead):

01local debounce = true
02local debouncetimer = 5 -- set this to how many seconds you want
03 
04script.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)
19end)
0
It didn't work, there were no errors, but it didn't give me any teddies. BunjiBloxxer 51 — 2y
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. kodymarcey 49 — 2y
0
I also edited the first script if you want it to only give one. Tell me if neither works. kodymarcey 49 — 2y
0
I get this error and am given no gear: Workspace.Model.Model.SecretRoom.Part.Script:25: attempt to index nil with 'Backpack' BunjiBloxxer 51 — 2y
0
Nvm I fixed it BunjiBloxxer 51 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

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

Answer this question