I’ve trying to make a thing where you can shoot projectiles through a key. And you can spam it alot with little cooldown between each shot.
But whenever I spam it too much, it delays the game alot. For example, when I spam it a lot for a while, the projectile usually phases through the target who was supposed to be damaged, missing entirely.
Here’s an example of what’s happening:
https://streamable.com/ayah6c
The quote system was meant to be a taunt. Before the latency begins, the words appear fast and smoothly, and the knives land perfectly, dealing damage. But when I begin to spam it, there’s an obvious latency for each word to appear, and later on, the knives begin to phase through the first target, hitting the ones behind, sometimes even phasing through all of them. I tried including it into a .Touched
function, which didn’t work out as expected. And I tried adding it into the debris service, which still didn’t work.
Here’s the example of my code, I’m not good at lua, so please tell me where did I do wrong.
cf = CFrame.new
ang = CFrame.Angles
rd = math.rad
rd2 = math.random
game:GetService("ReplicatedStorage").MIHKnife.OnServerEvent:Connect(function(player)
local chr = player.Character
local rarm = chr["Right Arm"]
local hed = chr["Head"]
local bruh = math.random(-1.5, 1.5)
local bruh2 = math.random(-1.5, 1.5)
local knife = game.ServerStorage.MIHKnife
thrown = true
local knoive = knife:Clone()
knoive.Parent = game.Workspace
knoive.CFrame = chr.HumanoidRootPart.CFrame * cf(bruh, bruh2, -3) * ang(rd(30), rd(0), rd(0))
game.Debris:AddItem(knoive, 5)
local yeet = Instance.new("BodyVelocity")
yeet.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
yeet.P = math.huge
yeet.Velocity = chr.HumanoidRootPart.CFrame.lookVector * 75
yeet.Parent = knoive
yeet.Name = "Force"
local traveldistance = 0
local function hito(part, partcfr, mag, dmg, debtim, debtime, bodyfdire, effect, grow, color)
--- [insert effects and damaging stuff]
end
end))
traveldistance = 20
end
end
end
end
coroutine.resume(coroutine.create(function()
repeat
wait()
traveldistance = traveldistance + 1
if traveldistance >= 20 then
knoive.Anchored = true
projectileemerald:Destroy()
end
if knoivethen
hito(knoive, knoive.CFrame * CFrame.new(0, 0, 0) * CFrame.new(math.random(-0.25, 0.25), math.random(-0.25, 0.25), math.random(-0.25, 0.25)) ,3, 10, 0.05, 0.05, projectileemerald.CFrame.lookVector * 10, "rbxassetid://241837157", 0.05, Color3.new(255, 0, 0))
end
until knoive == nil
end))
end)
Thank you!