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 1 year 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.

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)
0
Use something called debounce asmetics 26 — 1y

2 answers

Log in to vote
0
Answered by 1 year ago
Edited 1 year 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:

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)
0
It didn't work, there were no errors, but it didn't give me any teddies. BunjiBloxxer 51 — 1y
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 — 1y
0
I also edited the first script if you want it to only give one. Tell me if neither works. kodymarcey 49 — 1y
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 — 1y
0
Nvm I fixed it BunjiBloxxer 51 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

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

Answer this question