You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Hi! So I was making a knockback system which was good. But it was on client side and bad so I decided to rescript it.
-
What is the issue? Main problem is a collision delay. Im using GetPartsInParts() to check if there anything touched player. It works but with big delay. Here code.
local module = {}
local TweenService = game:GetService("TweenService")
function module.Knocback(Character,Speed,Velocity)
local Humanoid = Character.Humanoid --Character Humanoid
local HRP = Character.HumanoidRootPart --Character Humanoid root part
local Casting = true --Creating value to check if we must ray cast
local Floor = false --Creating value to check if we must fire floor ray cast
local KnockVelocity = Instance.new("BodyVelocity") --Creating body velocity
KnockVelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
KnockVelocity.Velocity = HRP.CFrame.lookVector * -Speed + Vector3.new(0,Velocity,0)
KnockVelocity.Parent = HRP
delay(.1,function() --Changing body velocity
KnockVelocity.MaxForce = Vector3.new(math.huge,100,math.huge)
KnockVelocity.Velocity = HRP.CFrame.lookVector * -Speed
Floor = true
end)
local KnockbackAnimation = Humanoid:LoadAnimation(script.Knockback)
KnockbackAnimation:Play()
local Hitbox = Instance.new("Part")
Hitbox.Name = "KnockbackHitbox"
Hitbox.Size = Vector3.new(4,4,4)
Hitbox.CanCollide = false
Hitbox.Anchored = false
Hitbox.Transparency = .8
Hitbox.Parent = Character
local weld = Instance.new("Weld",Hitbox)
weld.Part0 = Hitbox
weld.Part1 = HRP
weld.C0 = CFrame.new(0,1.2,0)
wait(.2)
spawn(function() --Spawn function start
while Casting == true do --While true loop start
print("ayo")
local Params = OverlapParams.new() --Creating raycast params
Params.FilterDescendantsInstances = {Character}
Params.FilterType = Enum.RaycastFilterType.Blacklist
local parts = workspace:GetPartsInPart(Hitbox,Params)
for i,v in pairs(parts) do
if v.CanTouch == true then
Casting = false
Hitbox:Destroy()
KnockVelocity:Destroy()
KnockbackAnimation:Stop()
end
end
wait()
end --While true loop end
end) --Spawn function end
end
return module
Here script in action.
- What solutions have you tried so far? I was using workspace:Raycast() and Ray.new() before. It had a delay too and so i looked up at dev forum to find bettter way to detect collision but delay is same. Is there any way to fix it?