local BodyVelocity = Instance.new("BodyVelocity")
BodyVelocity.MaxForce = Vector3.new(100000,100000,100000)
BodyVelocity.Velocity = Object.PrimaryPart.CFrame.LookVector * Speed
BodyVelocity.Parent = Object.PrimaryPart
local HB
HB = game:GetService("RunService").Heartbeat:Connect(function()
if Object and Object.Parent then
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Blacklist
Params.FilterDescendantsInstances = {workspace.VFX, Caster}
local Cast = workspace:Raycast(Object.PrimaryPart.Position, Object.PrimaryPart.CFrame.LookVector * 1.5, Params)
local hitPart
if Cast and Cast.Instance then
This part right here is where I check if a parts been hit. But sometimes it doesnât even get detected? Why is this?
Iâve seen projectiles that travel a lot faster though⌠And when the object hits the character itâs supposed to stick to them from where it hit. I canât just increase the length, or it will look like the projectile didnât hit them.
Projectile speed itself isnât the problem, its your raycast being way too short. You could try dynamically changing the ray length based on the speed of the projectile
Also, consider aliasing objects in your code so that itâs easier to read and edit
Also #2, you shouldnât be creating a new RBXScriptConnection binded to Heartbeat FOR EACH PROJECTILE, you can organize the hit registration system into a table and a loop
Also #3, you donât need to create a new RaycastParams object every time the projectile raycasts, its super redundant when you can create just one at the top of the script and use it over and over again
I tried your idea, little problem though the projectile detects something from like 10000 meters away. What should I do about that?
#1 Itâs a projectile script, so if I just named it âFireballâ that would be weird since itâs for more than 1 object that needs to go flying in a direction.
#2 Yeah I probably shouldnât use a Heartbeat each time, that would cause lag now that iâm thinking about it thanks for pointing that out.
#3 Uhh But if more vfx is parented into the vfx folder as the objects being fired thereâs a chance that it wonât blacklist that since itâs only blacklisting the old table of vfx?
I forgot that velocity is measured in studs per second and youâre doing hitreg on a per frame basis; you will also need to grab the delta-time from Heartbeat to ânormalizeâ the rayâs length
#1 What I meant by aliasing is using local variables to shorten the reference call of objects. For example, instead of doing Object.PrimaryPart over and over again whenever you want to use it, you can alias it to a local variable and use that instead:
Object and Object.Parent then
local prim = Object.PrimaryPart
#3 Whitelist/blacklist applies to all of the descendants of the instance in question. You donât have to worry about new children being parented, theyâre still whitelisted/blacklisted because their parents are