Projectile stays still?
I have been scripting a gun, and while doing so, after making the CFrame of the bullet slightly away from the weapon (to ensure no damage is taken to the player, and for effect), but doing so makes the bullet freeze. I have no idea on how to fix this, but I have isolated the area I think makes it do that. There is also no errors in the output, and the code after it works fine.
(In a localscript)
003 | local t = script.Parent |
005 | local MaxAmmo = script.MaxAmmo |
006 | local Ammo = script.Ammo |
007 | local AmmoPerClip = script.AmmoPerClip |
011 | local AmIEquipped = false |
013 | t.Equipped:connect( function () |
015 | local plr = game.Players:FindFirstChild(t.Parent.Name) |
016 | local m = plr:GetMouse() |
017 | m.Button 1 Down:connect( function () |
018 | if MaxAmmo.Value = = 0 then |
021 | Ammo.Value = Ammo.Value - 1 |
024 | local emag = Instance.new( "Part" , Workspace) |
025 | emag.FormFactor = "Custom" |
026 | emag.Size = Vector 3. new( 0.5 , 0.8 , 0.48 ) |
027 | emag.Position = h.Position - Vector 3. new( 0 , 1.5 , 0 ) |
028 | MaxAmmo = MaxAmmo - AmmoPerClip |
033 | local b = Instance.new( "Part" , Workspace) |
035 | b.BrickColor = BrickColor.new( "New Yeller" ) |
036 | b.FormFactor = "Custom" |
037 | b.Size = Vector 3. new( 0.05 , 0.05 , 1.3 ) |
038 | b.CFrame = h.CFrame * CFrame.new( 0 , 0 , - 3 ) |
039 | local v = Instance.new( "BodyVelocity" , b) |
040 | v.maxForce = Vector 3. new( math.huge , math.huge , math.huge ) |
041 | v.velocity = m.Hit.p* 50 |
044 | b.Touched:connect( function (hit) |
047 | if hit.Parent:IsA( "Model" ) and hit.Parent:FindFirstChild( "Humanoid" ) then |
048 | human = hit.Parent:FindFirstChild( "Humanoid" ) |
049 | if hit.Name = = "Head" then |
050 | human.Health = human.Health - 20 |
052 | elseif hit.Name = = "Torso" then |
053 | human.Health = human.Health - 15 |
056 | human.Health = human.Health - 10 |
060 | if human.Health = = 0 then |
061 | print 'the human has died' |
064 | print 'an inanimate object got shot! poor thing ;c' |
070 | m.KeyDown:connect( function (key) |
071 | if key = = "q" and running = = false then |
072 | local char = game.Players:FindFirstChild(t.Parent.Name).Character |
073 | local hum = char.Humanoid |
076 | elseif key = = "q" and running = = true then |
077 | local char = game.Players:FindFirstChild(t.Parent.Name).Character |
078 | local hum = char.Humanoid |
081 | elseif key = = "r" then |
082 | if MaxAmmo.Value = = 0 then |
086 | local emag = Instance.new( "Part" , Workspace) |
087 | emag.FormFactor = "Custom" |
088 | emag.Size = Vector 3. new( 0.5 , 0.8 , 0.48 ) |
089 | emag.Position = h.Position - Vector 3. new( 0 , 1.5 , 0 ) |
090 | MaxAmmo = MaxAmmo - AmmoPerClip |
097 | m.Button 2 Down:connect( function () |
098 | local cam = game.Workspace.CurrentCamera |
099 | if aiming = = false and AmIEquipped = = true then |
100 | t.GripPos = Vector 3. new(- 1 , 0 , 0 ) |
102 | cam.CameraType = "Attach" |
103 | cam.CameraSubject = s |
105 | elseif aiming = = true then |
106 | t.GripPos = Vector 3. new( 0 , 0 , 0 ) |
107 | print 'not aiming anymore' |
108 | cam.CameraType = "Custom" |
109 | cam.CameraSubject = plr.Character.Humanoid |
115 | t.Unequipped:connect( function () |