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

Why wont this gun script work?

Asked by 10 years ago
Player = game.Workspace.LocalPlayer                                                                                                                                                             
Gun = script.Parent                                                                                                                                                     
Ammo = 5                                                                                                                                                            
mouse = Player:GetMouse()                                                                                                                                                   
function Shoot()                                                                                                                                            
    if Ammo > 0 then                                                                                                                                
        Bullet = Instance.new("Part",  Workspace)                                                                                                               
        game.Debris:addItem(Bullet, 10)                                                                                                                                                                                                                                                     
        Bullet.Shape = "Ball"                                                                                                               
        Bullet.Size = Vector3.new(0.2,0.2,0.2)                                                                                                                  
        Bullet.TopSurface = "Smooth"                                                                                                                                                                                                                                        
        Bullet.BottomSurface = "Smooth"                                                                                                                                                                                             
        Bullet.BrickColor = BrickColor.new("Dark stone grey")                                                                                                                                           
        Bullet.CanCollide = false                                                                                                                               
        Bullet.CFrame = Gun.Handle.CFrame                                                                                                               
        Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)                                                                                                             
        v = Instance.new("BodyVelocity", Bullet)                                                                                                        
        v.velocity = Bullet.CFrame.lookVector *90                                                                                                           
        v.maxForce = Vector3.new(math.huge, math.huge, math.huge)                                                                                                           
    end                                                                                                                                                                         
end                                                                                                                                                                                 

Gun.Activated:connect(Shoot)

1 answer

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Well, you're skipping a line whlie setting the variable.. why?

Also, your direction may be off.

If this doesn't work then you're doing something wrong outside of the script.

local Player = game.Workspace.LocalPlayer
local Gun = script.Parent
local Ammo = 5
local mouse = Player:GetMouse()

Gun.Activated:connect(function()
    if Ammo > 0 then
        Bullet = Instance.new("Part",  Workspace)
        game.Debris:addItem(Bullet, 10)
        Bullet.Shape = "Ball"
        Bullet.Size = Vector3.new(0.2,0.2,0.2)
        Bullet.TopSurface = "Smooth"
        Bullet.BottomSurface = "Smooth"
        Bullet.BrickColor = BrickColor.new("Dark stone grey")
        Bullet.CanCollide = false
        Bullet.CFrame = Gun.Handle.CFrame
        Bullet.CFrame = CFrame.new(Bullet.Position,mouse.Hit.p)
        v = Instance.new("BodyVelocity", Bullet)
        v.velocity = Bullet.CFrame.lookVector * 90
        v.maxForce = Vector3.new(math.huge, math.huge, math.huge)
    end
end)
Ad

Answer this question