Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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.

1 comment

0

Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.