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

Gun Script help?

Asked by 8 years ago

Ok so i'm trying to make a gun and I was wondering how I would detect when the bullet hits a player? Here's my script so far:

player = game.Players.LocalPlayer
gun = script.Parent
mouse = player:GetMouse()

gun.Activated:connect(function()
    local b = Instance.new("Part", workspace)
    game.Debris:AddItem(b, 2)
    b.Shape = "Ball"
    b.TopSurface = "Smooth"
    b.BottomSurface = "Smooth"
    b.Size = Vector3.new(0.2, 0.2, 0.2)
    b.CanCollide = false
    b.Name = "Bullet"
    b.CFrame = gun.Handle.CFrame
    b.CFrame =  CFrame.new(b.Position, mouse.Hit.p)
    local v = Instance.new("BodyVelocity", b)
    v.Velocity = b.CFrame.lookVector*450
    v.MaxForce = Vector3.new(math.huge, math.huge. math.huge)
end)

And before you say, i have tried putting an on touch part that detects if what it hits has a humanoid, and it did not work when testing it on a dummy(which did have a Humanoid).

On a side note, when firing the gun, why do i get the error: "16:10:30.591 - Players.Player1.Backpack.Gun.LocalScript:18: attempt to index field 'huge' (a number value) 16:10:30.593 - Stack Begin 16:10:30.593 - Script 'Players.Player1.Backpack.Gun.LocalScript', Line 18" The gun works fine, but I don't know how to fix that.

Answer this question