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

Projectile stays still?

Asked by 11 years ago

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)

001print 'all is good'
002 
003local t = script.Parent
004local h = t.Handle
005local MaxAmmo = script.MaxAmmo
006local Ammo = script.Ammo
007local AmmoPerClip = script.AmmoPerClip
008local s = t.Sight
009local running = false
010local aiming = false
011local AmIEquipped = false
012 
013t.Equipped:connect(function()
014    AmIEquipped = true
015    local plr = game.Players:FindFirstChild(t.Parent.Name)
View all 117 lines...

2 answers

Log in to vote
0
Answered by 11 years ago

You are only moving the bullet once, while you need it to move constantly. Use a coroutine:

1function bM(b)
2    while wait(0.01) do
3        b.CFrame = h.CFrame * CFrame.new(0, 0, -3)
4    end
5end
6bulletMove = coroutine.wrap(bM);
7bulletMove(b); --Call this when you need the bullet to move
0
It seems to stick to the barrel and moves with it, but it doesn't go out and reach a target. lowvillan 10 — 11y
0
Nevermind, I fixed it. Thanks for your help. lowvillan 10 — 11y
0
No problem. PiggyJingles 358 — 11y
Ad
Log in to vote
0
Answered by 11 years ago

Might it be line 41?

Replace line 41 with v.velocity = (m.Hit.p - h.CFrame.p).unit*50 and see if that helps, because the way you had it, the velocity would be the mouse's hit position, instead of the direction to the mouse's hit position.

0
You fixed it, nevermind. :) PsychoWaffle 10 — 11y

Answer this question