of     1   

vm9
#139262694Saturday, July 05, 2014 12:14 AM GMT

Hello there fine scripters of ROBLOX. I have come across a dilemma. I decided it would be time to learn ROBLOX Lua and found a video that goes through on how to create a gun. Unfortunately, after following the tutorial almost word for word (changed the name of some variables, nothing large), I noticed that in the video the uploader's gun fired, but mine did not. If you are going to help me please keep in mind that I am not new to programming, but am new to ROBLOX Lua, and although I Googled every event, function name, property etc. that I did not know, I only have a basic understanding of them, so I ask that you make it understandable. I don't think there are code tags so here is the raw code. The documentation is for me by habit. ############################################################################## player = game.Players.LocalPlayer --Sets player as the LocalPlayer, LocalPlayer gets the play the LocalScript is in tool = script.Parent --Tool is set to parent of script mouse = Player:GetMouse() --Returns mouse in use by the client ammo = 10 --Ammo in gun --Fire procedure function fire () --If ammo is greater than 0 then a bullet is created if (ammo > 0) then bullet = Instance.new ("Part") --Creates a new instance of "Part" bullet.Parent = game.Workspace --Sets parent to workspace bullet.Name = "Bullet" --Sets name to "Bullet" bullet.Shape = "Ball" --Sets shape to ball bullet.Size = Vector3.new (1, 1, 1) --Sets size of bullet in X, Y, Z to 1 bullet.TopSurface = "Smooth" --Sets top surface of bullet to be smooth bullet.BottomSurface = "Smooth" --Sets bottom surface of bullet to be smooth bullet.BrickColor = BrickColor.new ("Toothpaste") --Sets color of bullet to "Toothpaste" which is cyanish bullet.CanCollide = false --Makes it so bullet goes through stuff bullet.CFrame = Gun.Handle.CFrame --CFrame in this case is the position, so I set position of bullet to the tool's handle bullet.CFrame = CFrame.new (bullet.Position, mouse.Hit.p) --Sets position of bullet to it's position, and made it point to where the mouse is aiming game.Debris:AddItem (bullet, 2) --Makes it so that 2 seconds after firing the bullet is removed v = Instance.new ("BodyVelocity", bullet) --Create instance of "BodyVelocity" for bullet, which allows me to apply force to the bullet v.velocity = Bullet.CFrame.lookVector * 90 --Sets speed that bullet moves at, in this case 90 v.maxForce = Vector3.new (math.huge, math.huge, math.huge) --Sets maximum speed that bullet can move at on the 3 axis to maximum end end --Activated listener, fired when mouse click while holding tool tool.Activated:connect (fire) ############################################################################### Thank you to whoever helps me. Once again, the problem is that the gun does not fire, nothing happens when I press the mouse button. Also the tutorial was Friaza Hyuga, "ROBLOX Scripting Tutorial 22 Making a Basic Gun" if that helps, I got to the 8:40 mark. Thanks. EDIT: This is a LocalScript inside the StarterPack
Frostglacier
#139262824Saturday, July 05, 2014 12:16 AM GMT

If the script is inside StarterPack it won't work. It should be in the gun itself.
vm9
#139262981Saturday, July 05, 2014 12:17 AM GMT

Sorry I should have been more descriptive. The script is inside a tool, which is inside the StarterPack.
vm9
#139270504Saturday, July 05, 2014 1:50 AM GMT

Bump
vm9
#139275869Saturday, July 05, 2014 2:56 AM GMT

Gotta bump again...
nobbers12345
#139276202Saturday, July 05, 2014 3:00 AM GMT

It appears that your gun does not have a function named "fire" which should find the velocity direction based on where you click. I hate the LGBT. Those laser guided battle tanks are just too damn powerful.
Frostglacier
#139276303Saturday, July 05, 2014 3:01 AM GMT

At the very top, you defined mouse as Player:GetMouse(), while player is defined only with a lowercase p. As it is, Lua is case-sensitive. Try making this edit to see if anything changes. If you want to see the errors in your script, when testing you can enable Output by right-clicking on the Studio toolbar and clicking "Output."

    of     1