Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I stop a projectile from following its CFrame after it has been shot?

I have a projectile I want to be launched forward from my character. Everything is good but the issue is that when I move my character a different direction after it has been shot the projectiles suddenly goes in that direction... Any ideas how to stop this here, is an example code:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Debris = game:GetService('Debris')

local Remote = ReplicatedStorage.EG.FlickEvent
local Shockwave = ReplicatedStorage.EG:FindFirstChild('Shockwave')
local Ring = ReplicatedStorage.EG:FindFirstChild('Ring')
local Damage = 2

local ServerDebounces = {}

Remote.OnServerEvent:Connect(function(plr, Mouse)
 if not ServerDebounces[plr] then
	wait(.4)
  ServerDebounces[plr] = true
  
  local Char = plr.Character or plr.CharacterAdded:Wait()

  local SmashRing = Ring:Clone() 
  SmashRing.CFrame = Char.HumanoidRootPart.CFrame * CFrame.new(0,0,0)
  SmashRing.Parent = workspace
 
  local SmashClone = Shockwave:Clone()
SmashClone.CFrame = Char.HumanoidRootPart.CFrame * CFrame.new(0,1.1,-3)
  SmashClone.Size = Vector3.new(20,20,25)
  SmashClone.Parent = workspace
 local BodyVelocity = Instance.new("BodyVelocity")
  BodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  BodyVelocity.Velocity = Vector3.new(0,0,0)
  BodyVelocity.Parent = SmashClone

 wait()
      for i = 0, 200 do
    wait()
    SmashClone.Orientation = SmashClone.Orientation + Vector3.new(0,0,5)
    BodyVelocity.Velocity = Char.HumanoidRootPart.CFrame.lookVector*i*5
	SmashRing.Size = SmashRing.Size + Vector3.new(0.2,0.2,0)*i
	SmashRing.Orientation = SmashRing.Orientation + Vector3.new(0,0,10)
	SmashRing.Transparency = SmashRing.Transparency - -0.01
	SmashClone.Transparency = SmashClone.Transparency - -0.01
	wait()
  ServerDebounces[plr] = false
  Debris:AddItem(SmashClone, 1.3)
  Debris:AddItem(SmashRing, 1)

 local Debounce = true
  SmashClone.Touched:Connect(function(h)
   if h.Parent:FindFirstChild('Humanoid') and h.Parent.Name ~= plr.Name and Debounce then  
    Debounce = false   
    local Enemy = h.Parent.Humanoid
    Enemy:TakeDamage(Damage)
    Debounce = false
    SmashClone:Destroy()
	wait(2)
	SmashRing:Destroy()
    Debounce = true
   end end)end end end)

6 comments

0

It's a simple fix, take the lookVector as a local variable. You're constantly access the variable through the actual object, you aren't detaching it.

0

BodyVelocity.Velocity = Char.HumanoidRootPart.CFrame.lookVectori5 << Make a variable called Char.HumanoidRootPart.CFrame.lookVector then do Vari5

0

Also make sure the variable is outside of the loop^^^^

0

Why can't he just summon the projectile infront of the character, and then the projectile's own lookVector as the means of travel?

0

@BaseUrl Thank you! I feel silly to have not seen such a simple fix! It works perfectly!

0

If you would like you can add this as an answer so I am able to accept your answer ^^

1 answer

I would suggest to delete the object after it has given damage.

This discussion is preserved as it was. New answers, comments, and votes are closed.