I’m having some issues with my force push code that baffles me. The program waits a second before actually applying the velocity despite there not being a wait in this entire script. Does anyone know what could be causing this delay?
local function forcePushEvent(plr)
local char = plr.Character
local root = char.HumanoidRootPart
--Special FX
local particles = particles.forcePushParticles.Attachment:Clone()
particles.Parent = char['Right Arm']
particles.CFrame = char['Right Arm'].RightGripAttachment.CFrame
for i,v in pairs(particles:GetChildren()) do
v:Emit(10)
end
debris:AddItem(particles, 3)
--Sound
local soundFx = sounds.forceSoundEffect:Clone()
soundFx.Parent = char['Right Arm']
soundFx:Play()
debris:AddItem(soundFx, 5)
--Scripting the knockback
local hitbox = Instance.new('Part')
hitbox.Parent = workspace
hitbox.Anchored = true
hitbox.CanCollide = false
hitbox.Transparency = 0.8
hitbox.Size = Vector3.new(10,10,50)
hitbox.CFrame = root.CFrame*CFrame.new(0,0,-50/2)
local pos1 = Vector3.new(hitbox.Position.X - (hitbox.Size.X / 2), hitbox.Position.Y - (hitbox.Size.Y /2), hitbox.Position.Z - (hitbox.Size.Z / 2))
local pos2 = Vector3.new(hitbox.Position.X + (hitbox.Size.X / 2), hitbox.Position.Y + (hitbox.Size.Y /2), hitbox.Position.Z + (hitbox.Size.Z / 2))
local hitboxRegion = Region3.new(pos1, pos2)
local charsFound = workspace:FindPartsInRegion3(hitboxRegion, nil, math.huge)
local alreadyHit = {}
for i,foundChar in pairs(charsFound) do
local hum = foundChar.Parent:FindFirstChild('Humanoid')
if hum and foundChar.Parent ~= char and not table.find(alreadyHit, foundChar.Parent) then
print('ran')
if foundChar.Parent.isBlocking.Value == false and foundChar.Parent.isParrying.Value == false then
--Knockback
ragdollModule.ragdoll(foundChar.Parent, ragdollTime)
local velocity = Instance.new('BodyVelocity')
velocity.Parent = foundChar.Parent.HumanoidRootPart
velocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
velocity.Velocity = root.CFrame.LookVector * forcepushKnockback
debris:AddItem(velocity, .1)
end
damageModule.magicDamage(char, foundChar.Parent, forcepushDamage)
table.insert(alreadyHit, foundChar.Parent)
end
end
--Getting rid of the hitbox
debris:AddItem(hitbox, .1)
table.clear(alreadyHit)
end
magicEvents.forcePush.OnServerEvent:Connect(forcePushEvent)