Hello, I have made a script that when a player clicks on a part it checks if a player already has a certain tool.
Everything works until the tool is not in the players backpack.
This is the script I used.
Script Below:
local tool = game.ServerStorage.Bat
local clone = tool:Clone()
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if plr.Character:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(plr.Character)
if plr.Backpack.Add and plr.Backpack.Add:IsA("Tool") then
print(plr.Name.." You already have a weapon!") -- Player already has a tool
else -- When player does not have a tool
script.Parent:Destroy()
if Clone.Parent ~= plr.Backpack then
Clone.Parent = plr.Backpack
end
end
end
end)
I have tried other methods but they do not work. Any help is appreciated!
A tool can be in two sites,
a) if the player is holding the tool then it’s in the player humanoid
b) if the player is not holding the tool is in the player backpack (game.Players[player.Name].Backpack[toolname]
I tried to fix a little the script and this is with what I came:
local tool = game.ServerStorage.Bat
local clone = tool:Clone()
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
if plr.Character:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(plr.Character)
if plr.Backpack:FindFirstChild("Tool Name") and plr.Backpack["Tool Name"] then
print(plr.Name.." You already have a weapon!") -- Player already has a tool
else -- When player does not have a tool
script.Parent:Destroy()
if Clone.Parent ~= plr.Backpack then
Clone.Parent = plr.Backpack
end
end
end
end)