alrighty, so im using a little script to spawn particles that do something. i am using a while loop to both check if they hit anything or if they should move forward. also, please, recommend me how i should reduce lag with custom physics because i feel that it may VERY VERY GREATLY impact my future projects. anyway heres the script!!
for i = 0, math.random(10, 11), 1 do
task.spawn(function()
local frag = game.ReplicatedStorage.otherstuffs.frag:Clone()
local width = frag.Size.X + math.random(-10,100)/100
frag.Size = Vector3.new(width, frag.Size.Y - math.random(-10, 10)/10, width)
frag.Position = Rocket.Position + Vector3.new(0, 1, 0)
local deltatime = 0.017
debris:AddItem(frag, 5)
local dir = Vector3.new(math.random(-20, 20), 50, math.random(-20, 20))
local param = RaycastParams.new()
param.CollisionGroup = "projectile"
local destroyed = false
frag.Destroying:Connect(function() destroyed = true end)
frag.Parent = workspace
while not destroyed do
local raycastresult = workspace:Raycast(frag.Position, Vector3.new(dir.Unit.X * 2, dir.Y, dir.Unit.Z * 2) * deltatime, param)
print("started loop")
if raycastresult then
print("found ray")
frag.Position = raycastresult.Position
frag.Anchored = false
local hum = raycastresult.Instance.Parent:FindFirstChildOfClass("Humanoid")
if hum and game.Players:GetPlayerFromCharacter(hum.Parent) == nil then
damagemodule.DamageZombie(game.ReplicatedStorage.weapons.RocketLauncher.damage.Value * CreatorTag.Value.Character.damageBUFF.Value, true, "explosion", CreatorTag.Value, hum.Parent, 6)
end
return
else
print("moved em")
frag.Position += dir * deltatime
dir = dir * (1 - 0.05 * deltatime) + Vector3.new(0, -workspace.Gravity * deltatime, 0)
frag.CFrame = CFrame.lookAt(frag.Position, frag.Position + dir) * CFrame.Angles(-math.pi/2,0,0)
_, deltatime = runserv.Stepped:Wait()
task.wait()
end
end
end)
end
by the way, this functions like a charm until i make more of these particles. im sure that the lag is here because of all the moving that i do in the while loop but im not sure how to fix this…