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

How to make a tool giver that does not give the tool to players if they already have it?

Asked by 4 years ago
Edited 4 years ago

How can I make a tool giver that detects the player's backpack and only give a tool to the player only if the player does not have the tool? If the player have the tool, the tool giver will not give the player the tool.

Here's the code that gives the player the tool multiple times:

function boop(Player)
 if not Player.Backpack:FindFirstChild(Gun) then
  local Tool = game.Lighting[Gun]:clone()
  Tool.Parent = Player.Backpack
 end
end
script.Parent.ClickDetector.MouseClick:Connect(boop)

0
Where is your code for the giver? SteamG00B 1633 — 4y
0
Oh, I have put it inside already SUPERMEGADANTHEMAN 33 — 4y
0
Is Toolname a variable that is already defined? lukasdim -3 — 4y
0
Yes SUPERMEGADANTHEMAN 33 — 4y

1 answer

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

You also need to check if they are currently holding the tool, in which case it will be in their character model

function boop(Player)
    local ToolName = Tool.Name
    if not Player.Backpack:FindFirstChild(ToolName) then
        if not Player.Character:FindFirstChild(ToolName) then
            --Code for cloning the tool would go here 
        end
    end
end

I haven't tested this code, but it should work in theory

Ad

Answer this question