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

Whenever the player touches the brick, the gun isn't given?

Asked by 4 years ago
Edited 4 years ago

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.

1 answer

Log in to vote
0
Answered by 4 years ago

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.

0
Thanks! Spookdoggz 42 — 4y
Ad

Answer this question