✓ Accepted answer
We just check if something doesn't exist in the player's backpack.
#FindFirstChild
FindFirstChild finds if there is a child there. If it is there is will return with the object, If not, it will return nil meaning nothing.
game:GetService("Players").PlayerAdded:connect(function(plyr)
plyr.CharacterAdded:connect(char)
if char:FindFirstChild("Humanoid") ~= nil then
print("humanoid found")
end
end
end)
~= nil means not nil, if the function can't find the child then it returns nil, but since it can, it can print. Also, instead of seeing if it isn't nil you can see if it's true
game:GetService("Players").PlayerAdded:connect(function(plyr)
plyr.CharacterAdded:connect(char)
if char:FindFirstChild("Humanoid") then
print("humanoid found")
end
end
end)
if char:FindFirstChild("Humanoid") then is the same as if char:FindFirstChild("Humanoid") == true then.
#Final Product
local part = script.Parent;
local clickDetector = part.ClickDetector;
function onMouseClick(player)
if not player.Backpack:FindFirstChild("Sabre") and not player.Character:FindFirstChild("Sabre") then
game.Lighting["Sabre"]:Clone().Parent = player.Backpack;
end
end
clickDetector.MouseClick:connect(onMouseClick);
Hope it helps!
Tip: Make sure you're unable to drop the tool because people could drop the tool, click the part again, and then pick up the old one and he'll have 2 sabres.
1 comment
I edit my answer, you should look at my new final product.