Here's the script.
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) if player.Backpack.LaserGun == nil then local gunClone = gun:Clone() gunClone.Parent = player.Backpack end end end)
The error is ("LaserGun is not a valid member of Backpack") Which is exactly what I want so I can give the player a gun, but it's still not given.
Ok, it's very simple. You're trying to find out if it exists, right? Change your script to this!
script.Parent.Touched:Connect(function(hit) if hit.Parent:FindFirstChildWhichIsA("Humanoid") ~= nil then local player = game.Players:GetPlayerFromCharacter(hit.Parent) local Gun == player.Backpack:FindFirstChild("LaserGun") if Gun == nil then local gunClone = gun:Clone() gunClone.Parent = player.Backpack end end end)
You never ask if it's nil in order to find out if something exists. Instead, you FindFirstChild
and then ask if that exists.