I am trying to create a tool dispenser, thank you dyler3, essentially a giver, that would clone a tool into the players backpack when a certain part is touched. Only after testing it the script clones multiple tools into my backpack and I wanted to know how to stop the script from running after the player had received a single tool. What would I include? Here is the script:
script.Parent.Touched:connect(function(Part)
if Part.Parent:FindFirstChild("Humanoid") then
local player=game.Players:GetPlayerFromCharacter(Part.Parent)
game.ReplicatedStorage.Tool:clone().Parent=player.Backpack
end
end)
Could I possibly make it check the players backpack for the specific tool and if it does find the tool, wait 2.5 seconds using an if, then statement beforehand? I tried something like this:
script.Parent.Touched:connect(function(Part)
if Part.Parent:FindFirstChild("Humanoid") then
if player.Backpack:FindFirstChild("Tool") then
wait(2.5)
local player=game.Players:GetPlayerFromCharacter(Part.Parent)
game.ReplicatedStorage.Tool:clone().Parent=player.Backpack
end
end
But then that would mean that you would have to already have the tool to get the tool. How would I exclude lines 5 and 6 from the statement on line 3 and 4; how would I run it separately of that, yet beforehand?
Or could I possibly stop the script from creating another thread for a specific amount of time? So only one thread would run at a time and there would also be included a sort of cooldown?

4 comments
Post the script.
Have you tried using a Debounce? A Debounce is used to prevent a Function from firing multiple times on Execution. Also, there is a Documentary about this subject on the Roblox WIKI. :) Wiki Documentary on Debounce: http://wiki.roblox.com/index.php?title=Debounce
I did try using debounce, but I am not sure if I am using it correctly, because it did not work.
Could somebody show me how to properly use 'debounce' for this situation so I could check it and make sure I used it right? Because like I said earlier...