Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I make a giver script that if the player has the tool already, it is not given?

This is my script so far, it can be spammed for infinite tools, how do I make it so that if the player already has said tool, it isn't given to the player?

plr = game.Players.LocalPlayer
tool = game.ServerStorage["Knife"]

script.Parent.MouseButton1Down:connect(function()
    tool:clone().Parent = plr.Backpack
end)

Thanks!

2 comments

0

You called use a debounce, or just check their backpack and make sure they don't have another copy of the tool.

0

But how do I check the backpack?

2 answers

✓ Accepted answer

Use FindFirstChild to check for the tool.

plr = game.Players.LocalPlayer
tool = game.ServerStorage["Knife"]
 
script.Parent.MouseButton1Down:connect(function()
if plr.Backpack:FindFirstChild("Knife") == nil then
    tool:clone().Parent = plr.Backpack
else return end
end)

Something like this I think

2 comments

0

I was halfway through making another script, this is much more efficient.

0

Pretty sure that code you just wrote would let them get two knifes, if they hold the tool. When a tool is held in the hand, its in the character instead of the backpack. You'd have to check both of them

This discussion is preserved as it was. New answers, comments, and votes are closed.