Enhancing Projectile?

Nah, not really.

these two lines could be replaced with:

while SpellPart do

(but you can also remove the loop entirely, keep reading)

wait() sort of sucks. It’s fine, but better is to attach your update to the actual physics updates with the https://developer.roblox.com/en-us/api-reference/event/RunService/Stepped event:

game:GetService("RunService").Stepped:Connect(function(time, step)
    -- do stuff in here that you want to be called every frame
end)

Now because we don’t have a loop we can’t break, but we can disconnect the event:

local connection
connection = game:GetService("RunService").Stepped:Connect(function(time, step)
    if not SpellPart then
        connection:Disconnect()
        return
    end
    -- etc
    -- also for the other 'break'
end)

(both places you do this) you shouldn’t just multiply by SpellSpeed, because frames (either with the loop and wait(), or with Stepped) aren’t always the same length. Better is to use the step argument of Stepped (or the return value of wait()) to scale your speed by the time of the frame:

local connection
-- BTW 'Stepped' might be called 'PostSimulation' now/in the future but I've never
-- tested that
connection = game:GetService("RunService").Stepped:Connect(function(time, step)
    -- ...
    local StudsToMove = SpellSpeed * step -- use this where you used SpellSpeed before
    -- ...
end)

Just note that your SpellSpeed would be in studs/second units now, so it’ll probably need to be much bigger (~30x) than what you had before.

1 Like