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

Why won't this gun script work?

Asked by 9 years ago

I have this script:

function FireBullet(pos)
    script.Parent.Handle.LaserShot:Play()
    local p=Instance.new("Part")
    p.Parent=game.Workspace
    p.FormFactor="Custom"
    p.Size=Vector3.new(0.4,0.4,1)
    p.Name="LaserBullet"
    p.CFrame=CFrame.new(script.Parent.Handle.Position)
    p.TopSurface="Smooth"
    p.BottomSurface="Smooth"
    p.Color=Color3.new(0,255,0)
    p.CanCollide=false
    p.Anchored=false
    local l=Instance.new("PointLight")
    l.Parent=p
    l.Color=Color3.new(0,255,0)
    l.Shadows=true
    l.Range=15
    local v=Instance.new("BodyVelocity")
    v.Parent=p
    v.velocity=pos-script.Parent.Handle.Position
    local g=Instance.new("BodyGyro")
    g.Parent=p
    local po=script.Parent.Handle.Position
    g.cframe=CFrame.new(Vector3.new(po.x,po.y,po.z),(CFrame.new(pos).p-Vector3.new(po.x,po.y,po.z)).unit*300)


    p.Touched:connect(function(part)
        if part.Parent:FindFirstChild("Humanoid") then
            if not part.Parent.Name==script.Parent.Parent.Name then
                script.Parent.Handle.LaserHit:Play()
                part.Parent.Humanoid:TakeDamage(25)
                p:remove()
            end
        end
    end)
    wait(10)
    if p.Parent==game.Workspace then
        p:remove()
    end
end

script.Parent.Equipped:connect(function(mouse)
    mouse.Button1Down:connect(function()
        FireBullet(mouse.Hit.p)
    end)
end)

I want this script to make a bullet appear at the handle of the tool, then move to where the player clicked to fire the bullet.

It should work but the only problem is that the bullet won't move after I have clicked, is there something wrong with the script? The output won't give me anything.

0
Try increasing the maxForce and velocity of the BodyVelocity, because currently it is quite low, and will not do much. Diitto 230 — 9y
1
Increased it to math.huge and it still didn't move 73epic311 13 — 9y
0
Hm. I haven't worked with BodyVelocities that much, instead preferring to go with CFrame, so I can't think of any decent way of fixing this. Also, try doing p:breakJoints(), for it may have welded to the handle. Oh, and math.huge will just make it do nothing for velocity. Make the velocity something decent. Diitto 230 — 9y
0
That kind of helped 73epic311 13 — 9y

1 answer

Log in to vote
0
Answered by
yoshiegg6 176
9 years ago
 g.cframe=CFrame.new(Vector3.new(po.x,po.y,po.z),(CFrame.new(pos).p-Vector3.new(po.x,po.y,po.z)).unit*300)

I'm not sure if this is the only problem but you don't use vector3 with cframe. Use this instead.

 g.CFrame = CFrame.new(po.x,po.y,po.z),(CFrame.new(pos).p-CFrame.new(po.x,po.y,po.z)).unit*300)
0
That wasn't the problem 73epic311 13 — 9y
0
*not the only problem. You can't use vector3 with cframe. yoshiegg6 176 — 9y
Ad

Answer this question