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

Why touch event not working for non real players in a laser gun bullet?

Asked by 3 years ago

I made a little gun that shoots laser bullets and detecting if it hit a player using .Touched event then checking for humanoid, it works completely fine with real players but when I hit a NPC or a wall with it it doesn't even detect a hit, which is really bad as the gun holder can't shoot zombies and can shoot players through walls

here is my gun code:

    local core = tool.Handle.Core
    local laser = Instance.new('Part', tool)
    laser.Name = 'Laser'
    laser.Size = Vector3.new(1, 1, distance)
    laser.CFrame = CFrame.new(core.Position, mousePos)
    laser.Position = laser.Position + laser.CFrame.LookVector * distance / 2

    laser.Touched:Connect(function(hit)
        print(hit) -- doesn't print anything when I shoot against the wall or npc, but prints what hit when it's actual player
    end)

    wait(0.25)
    laser:Destroy()

Answer this question