Help with Duplicated tool

for some reason, my tool is duplicated many times and I want to prevent that, does anyone know about this? please help me.

   Script:

         local price = 1200
         local db = true
         script.Parent.ClickDetector.MouseClick:Connect(function(player)
         	if player.leaderstats.Cash.Value >= price then
         		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
        		db = false
         		game.Lighting["1# Feathers Texture BB"]:clone().Parent = player.Backpack
         		wait(2)
         		db = true
         	end
         end)

13a

1 Like

Because you are cloning the tool each time player Click.

Try this:

        local price = 1200
        local db = true
        local ToClone = game.Lighting["1# Feathers Texture BB"]:Clone() 
         script.Parent.ClickDetector.MouseClick:Connect(function(player)
         	if player.leaderstats.Cash.Value >= price then
         		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
        		db = false
         		ToClone.Parent = player.Backpack
         		wait(2)
         		db = true
         	end
         end)
3 Likes

How can I make that not happen and you can only buy it 1 time?

I edited your code try it now. ^

1 Like

Hey, thank you so much for the help I didn’t know what I was doing :joy:

And also to prevent it to be bought again edit it like this:

        local price = 1200
        local db = true
        local ToClone = game.Lighting["1# Feathers Texture BB"]:Clone() 
         script.Parent.ClickDetector.MouseClick:Connect(function(player)
         	if player.leaderstats.Cash.Value >= price and not player.Backpack:FindFirstChild(["1# Feathers Texture BB"]) then
         		player.leaderstats.Cash.Value = player.leaderstats.Cash.Value - price
        		db = false
         		ToClone.Parent = player.Backpack
         		wait(2)
         		db = true
         	end
         end)
2 Likes

It’s okay glad that I helped you :)!

1 Like

oooh that’s what I was going to tell you

Something is wrong here

Try it now I edited my code a little.

1 Like
local Lighting = game:GetService("Lighting")
local Tool = Lighting:WaitForChild("1# Feathers Textures BB")
local DB = false
local Click = script.Parent
Click.MouseClick:Connect(function(Player)
       if Player.leaderstats.Cash.Value >= price and not Player.Backpack:FindFirstChild("1# Feathers Textures BB") and not DB then
              DB = true
              Player.leaderstats.Cash.Value -= price
              Tool:Clone().Parent = Player.Backpack
              wait(2)
              DB = false
       end
end)

Optimized script.

1 Like