I made a script so if you touch a part you get a sword. I made it so you'll only get one sword. However, if you equip the sword it would give you an extra sword. How would I fix this? Here is the script:
script.Parent.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
local sword = game.ReplicatedStorage.Sword:Clone()
-- Detects if the part that 'hit' the brick contains a Humanoid
wait()
if plr.Backpack:FindFirstChild("Sword") then
else
if hit.Parent.Humanoid then
-- Function GetPlayerFromCharacter returns the Character associated with the player (hit.Parent)
-- Clones tool into player's backpack
sword.Parent = plr.Backpack
end
end
end)

2 comments
Please put this in a code block so i can understand this more.
Fixed.