Hi all! I have been making a battlegrounds game and along with the successes I have had many flaws. One of which is a few bugs that I don’t know how to patch.
A.) Sometimes the HumanoidRootPart anchors forever instead of for 0.5 seconds
B.) Sometimes the knockback doesn’t happen and just the knockback animation plays.
I’ve tried editing the scripts order and it didn’t work no matter what.
everything else is working perfectly, AND PLEASE DO NOT nitpick this post. yes my script is messy, but only say things that are DIRECTLY the problem. If you want to make my script perfect, do it yourself! Thank you in advance.
The code:
SERVER SIDE
local rs = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
function Knockback(KnockbackSource, Player, Intensity)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(250000,250000,250000)
bv.Velocity = -(KnockbackSource.Position - Player.HumanoidRootPart.Position).Unit*Intensity
bv.Parent = Player
game.Debris:AddItem(bv, 0.5)
end
rs.DamageDealer.OnServerEvent:Connect(function(plr, attackcycle, cooldown)
if cooldown == true then
local HRP = plr:FindFirstChild("HumanoidRootPart")
local Params = RaycastParams.new()
Params.FilterType = Enum.RaycastFilterType.Exclude
Params.FilterDescendantsInstances = {plr.Character}
rayDistance = 25 --// 3 studs
origin = plr.Character:FindFirstChild("HumanoidRootPart").Position --// Position of the player
direction = plr.Character:FindFirstChild("HumanoidRootPart").CFrame.LookVector * rayDistance --// Direction the player is looking * distance
raycast = workspace:Raycast(origin, direction ,Params)
local function Ray()
return raycast and raycast.Position or origin + direction
end
print(Ray())
print(plr.Character:FindFirstChild("Head").Orientation.X)
if attackcycle == 1 then
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
task.wait(0.01)
local Football = game:GetService("ReplicatedStorage").Football:Clone()
Football.Parent = workspace
Football.Position = Vector3.new(plr.Character:WaitForChild("Left Leg").Position.X, plr.Character:WaitForChild("Left Leg").Position.Y, plr.Character:WaitForChild("Left Leg").Position.Z + 3)
local Tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false)
local FootballTween = TS:Create(Football, Tweeninfo, {["Position"]=(Ray())})
FootballTween:Play()
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
FootballTween.Completed:Once(function()
Football:Destroy()
task.wait(0.2)
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
end)
end
if attackcycle == 2 then
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
task.wait(0.01)
local Football = game:GetService("ReplicatedStorage").Football:Clone()
local Tweeninfo = TweenInfo.new(0.5, Enum.EasingStyle.Exponential, Enum.EasingDirection.Out, 0, false)
Football.Parent = workspace
Football.Position = Vector3.new(plr.Character:WaitForChild("HumanoidRootPart").Position.X, plr.Character:WaitForChild("HumanoidRootPart").Position.Y, plr.Character:WaitForChild("HumanoidRootPart").Position.Z + 3)
local FootballTween = TS:Create(Football, Tweeninfo, {["Position"]=(Ray())})
FootballTween:Play()
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
FootballTween.Completed:Once(function()
Football:Destroy()
task.wait(0.2)
end)
end
if attackcycle == 3 then
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
task.wait(0.01)
local Football = game:GetService("ReplicatedStorage").Football:Clone()
local SpecialTweeninfo = TweenInfo.new(0.25, Enum.EasingStyle.Exponential, Enum.EasingDirection.In, 0, false)
Football.Parent = workspace
Football.Position = Vector3.new(plr.Character:WaitForChild("Left Leg").Position.X, plr.Character:WaitForChild("Left Leg").Position.Y, plr.Character:WaitForChild("Left Leg").Position.Z + 3)
local FootballTween = TS:Create(Football, SpecialTweeninfo, {["Position"]=(Ray())})
FootballTween:Play()
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
FootballTween.Completed:Once(function()
FootballTween:Play()
task.wait(0.25)
Football:Destroy()
task.wait(1)
end)
end
if attackcycle == 4 then
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = true
task.wait(0.01)
local Football = game:GetService("ReplicatedStorage").Football:Clone()
local SpecialTweeninfo = TweenInfo.new(0.125, Enum.EasingStyle.Exponential, Enum.EasingDirection.In, 0, false)
Football.Parent = workspace
Football.Position = Vector3.new(plr.Character:WaitForChild("Left Leg").Position.X, plr.Character:WaitForChild("Left Leg").Position.Y, plr.Character:WaitForChild("Left Leg").Position.Z + 3)
local FootballTween = TS:Create(Football, SpecialTweeninfo, {["Position"]=(Ray())})
FootballTween:Play()
plr.Character:FindFirstChild("HumanoidRootPart").Anchored = false
FootballTween.Completed:Once(function()
FootballTween:Play()
task.wait(0.2)
Football:Destroy()
task.wait(0.3)
end)
end
--detects if it hit a part of a character with a humanoid
if raycast and raycast.Instance.Parent:FindFirstChild("Humanoid") then
local hum = raycast.Instance.Parent:FindFirstChild("Humanoid")
local char = hum.Parent
local humanoid = char:FindFirstChild("Humanoid")
local humroot = char:FindFirstChild("HumanoidRootPart")
local anim: Animator = hum:FindFirstChild("Animator")
local animtrack = anim:LoadAnimation(script.Hit)
animtrack:Play()
char:FindFirstChild("Torso").Anchored = true
if attackcycle == 1 or 2 or 3 or 4 then
humanoid:TakeDamage(1)
if attackcycle == 2 or 3 or 4 then
humanoid:TakeDamage(2)
if attackcycle == 3 or 4 then
humanoid:TakeDamage(3)
if attackcycle == 4 then
humanoid:TakeDamage(4)
rs.KnockbackGiverPlus:FireClient(game.Players:GetPlayerFromCharacter(char),humroot, plr)
task.wait(0.5)
char:FindFirstChild("Torso").Anchored = false
local animtrack2 = anim:LoadAnimation(script.KnockedBack)
animtrack2:Play()
end
end
end
end
end
end
end)
CLIENT SIDE
function KnockbackPlus(KnockbackSource, Player)
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(250000,250000,250000)
bv.Velocity = -(KnockbackSource.Position - Player.Position).Unit*125
bv.Parent = Player
game.Debris:AddItem(bv, 0.5)
end
game:GetService("ReplicatedStorage").KnockbackGiverPlus.OnClientEvent:Connect(function(humroot, plr)
print("aaa I've been knocked")
KnockbackPlus(plr.Character.HumanoidRootPart, humroot)
end)