The firing part of the pistol isn't working?
Hello, I am working on a game in ROBLOX called Dreadfire. I am scripting the guns, but i've run into a problem..
So basically, this is a local script inside of the tool. Everything works in it except for the activated part. The only thing that works is the sound. and when I test it, I do not see a bullet firing out of the chamber. Any help?
I also had taken the script from the laser pistol ROBLOX created, but tried to modify it.
08 | local NOZZLE_OFFSET = Vector 3. new( 0 , 0.4 , - 1.1 ) |
14 | local PlayersService = game:GetService( 'Players' ) |
15 | local DebrisService = game:GetService( 'Debris' ) |
17 | local Tool = script.Parent |
18 | local Handle = Tool:WaitForChild( 'Handle' ) |
20 | local FireSound = Handle:WaitForChild( 'Fire' ) |
21 | local ReloadSound = Handle:WaitForChild( 'Reload' ) |
32 | local function FindCharacterAncestor(subject) |
33 | if subject and subject ~ = workspace then |
34 | local humanoid = subject:FindFirstChild( 'Humanoid' ) |
36 | return subject, humanoid |
38 | return FindCharacterAncestor(subject.Parent) |
44 | local function BaseShot() |
45 | local Burst = Instance.new( 'Part' ) |
47 | BaseShot.FormFactor = Enum.FormFactor.Custom |
48 | BaseShot.Size = Vector 3. new( 0.2 , 0.2 , 3 ) |
49 | BaseShot.CanCollide = false |
50 | BaseShot.BrickColor = BrickColor.new( "Electric blue" ) |
51 | BaseShot.Material = "Neon" |
54 | local function OnTouched(shot, otherPart) |
55 | if otherPart.Name = = "Sensor" then |
56 | if otherPart.Parent.Parent.Parent.Name = = "Green Vest" then |
57 | script.Parent.Points = script.Parent.Points + 25 |
62 | local function OnEquipped() |
63 | Character = Tool.Parent |
64 | Humanoid = Character:WaitForChild( 'Humanoid' ) |
65 | Player = PlayersService:GetPlayerFromCharacter(Character) |
68 | local function OnActivated() |
69 | if Humanoid.Health > 0 then |
74 | local handleCFrame = Handle.CFrame |
75 | local firingPoint = handleCFrame.p + handleCFrame:vectorToWorldSpace(NOZZLE_OFFSET) |
76 | local shotCFrame = CFrame.new(firingPoint, Humanoid.TargetPoint) |
78 | local laserShotClone = BaseShot() |
79 | laserShotClone.CFrame = shotCFrame + (shotCFrame.lookVector * (BaseShot.Size.Z / 2 )) |
80 | local bodyVelocity = Instance.new( 'BodyVelocity' ) |
81 | bodyVelocity.velocity = shotCFrame.lookVector * SHOT_SPEED |
82 | bodyVelocity.Parent = laserShotClone |
83 | DebrisService:AddItem(laserShotClone, SHOT_TIME) |
98 | Tool.Equipped:connect(OnEquipped) |
99 | Tool.Activated:connect(OnActivated) |