so this is my script for a barrage but my problem is the stun inside of it is really bad [as seen in the video]: Streamable
So that is the script (the stun stuff is inside of the .touched function) :
local RS = game:GetService("ReplicatedStorage")
local tweenService = game:GetService("TweenService")
local RagodllModule = require(RS.Modules.Ragdoll)
local PlayersHit = {}
local PlayersHit2 = {}
local activated = false
local RightHit = Instance.new("Animation")
RightHit.AnimationId = "rbxassetid://13474679772"
local LeftHit = Instance.new("Animation")
LeftHit.AnimationId = "rbxassetid://13474685794"
local StunnedGui = RS.Effects:WaitForChild("Stunned")
--Settings--
local damage = 1 --how much damage it deals
local pushForce = 1.5 --knockback
--Settings--
function keepSpeed(plr)
while activated == true do
plr.Character.Humanoid.WalkSpeed = 5
task.wait()
end
end
function HitboxFunction(hitbox)
while activated == true do
hitbox.CanTouch = true
hitbox.Transparency = 1
task.wait(0.2)
hitbox.CanTouch = false
hitbox.Transparency = 1
end
end
RS.Events.Barrage.OnServerEvent:Connect(function(plr)
plr.Character.Humanoid.WalkSpeed = 5
activated = true
RS.Events.Barrage:FireClient(plr)
coroutine.wrap(keepSpeed)(plr)
local PunchSwingSound = script["Punch Swing "]:Clone()
PunchSwingSound.Parent = plr.Character.HumanoidRootPart
PunchSwingSound:Play()
game:GetService("Debris"):AddItem(PunchSwingSound,4)
local Trail = RS.Effects:WaitForChild("Trail"):Clone()
Trail.Parent = plr.Character.HumanoidRootPart
Trail.Attachment0 = plr.Character["Left Arm"].LeftShoulderAttachment
Trail.Attachment1 = plr.Character["Left Arm"].LeftGripAttachment
local Trail2 = RS.Effects:WaitForChild("Trail"):Clone()
Trail2.Parent = plr.Character.HumanoidRootPart
Trail2.Attachment0 = plr.Character["Right Arm"].RightShoulderAttachment
Trail2.Attachment1 = plr.Character["Right Arm"].RightGripAttachment
local plrhighlight = Instance.new("Highlight")
plrhighlight.Parent = plr.Character
plrhighlight.DepthMode = Enum.HighlightDepthMode.Occluded
plrhighlight.FillTransparency = 0
plrhighlight.FillColor = Color3.fromRGB(255, 255, 255)
plrhighlight.OutlineTransparency = 1
game:GetService("TweenService"):Create(plrhighlight, TweenInfo.new(3, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true), {FillTransparency = 1}):Play()
game.Debris:AddItem(plrhighlight, 3)
local hitbox = Instance.new("Part", plr.Character)
hitbox.Anchored = false
hitbox.CanCollide = false
hitbox.Size = plr.Character.HumanoidRootPart.Size * 2
hitbox.CFrame = plr.Character.HumanoidRootPart.CFrame * CFrame.new(0, 0, -2.5)
hitbox.Color = Color3.fromRGB(255, 0, 0)
hitbox.Transparency = 1
local hitboxWeld = Instance.new("ManualWeld")
hitboxWeld.Name = "HitboxWeld"
hitboxWeld.Part0 = hitbox
hitboxWeld.Part1 = plr.Character.HumanoidRootPart
hitboxWeld.C0 = hitbox.CFrame:ToObjectSpace(plr.Character.HumanoidRootPart.CFrame)
hitboxWeld.Parent = hitbox
coroutine.wrap(HitboxFunction)(hitbox)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and activated == true and PlayersHit[hit.Parent] == nil then
if hit.Parent.Values.Iframes.Value == false and hit.Parent ~= plr.Character then
PlayersHit[hit.Parent] = true
local enemy = hit.Parent
local enemyhum = enemy:WaitForChild("Humanoid")
enemyhum.WalkSpeed = 1
enemyhum.JumpHeight = 1
local ui = StunnedGui:Clone()
ui.Parent = hit.Parent.Head
game.Debris:AddItem(ui, .2)
hit.Parent.Values.Stunned.Value = true
enemy:WaitForChild("Humanoid"):TakeDamage(damage)
enemy.HumanoidRootPart.CFrame = CFrame.lookAt(hit.Parent.HumanoidRootPart.Position, plr.Character.HumanoidRootPart.Position)
local track1 = enemyhum:LoadAnimation(RightHit)
track1:Play()
local BloodEffect = RS.Effects:WaitForChild("Blood").Attachment:Clone()
BloodEffect.Parent = enemy.HumanoidRootPart
game:GetService("Debris"):AddItem(BloodEffect,1)
local HitEffect = RS.Effects:WaitForChild("Hit").Attachment:Clone()
HitEffect.Parent = enemy.HumanoidRootPart
HitEffect.ParticleEmitter:Emit(10)
game:GetService("Debris"):AddItem(HitEffect,1)
local PunchSound = script.Punch:Clone()
PunchSound.Parent = plr.Character.HumanoidRootPart
PunchSound:Play()
game:GetService("Debris"):AddItem(PunchSound,.6)
local vel = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = hit.Parent.HumanoidRootPart
vel.Velocity = Vector3.new(1,1,1) * plr.Character:WaitForChild("HumanoidRootPart").CFrame.LookVector * pushForce
vel.Name = "SmallMoveVel"
game.Debris:AddItem(vel,0.4)
local highlight = Instance.new("Highlight")
highlight.Parent = enemy
highlight.DepthMode = Enum.HighlightDepthMode.Occluded
highlight.FillTransparency = 0
highlight.OutlineTransparency = 1
game:GetService("TweenService"):Create(highlight, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true), {FillTransparency = 1}):Play()
game.Debris:AddItem(highlight, 1)
if plr:WaitForChild("RageValues").Ultimate.Value == false then
plr:WaitForChild("RageValues").RageValue.Value += damage / 2
end
local EnemyScript = script.EnemyScript:Clone()
EnemyScript.Parent = enemy
EnemyScript.Disabled = false
game.Debris:AddItem(EnemyScript,1)
task.wait(.2)
PlayersHit[hit.Parent] = nil
task.wait(.3)
if enemy.Values.Stunned.Value == true then
enemyhum.WalkSpeed = 16
enemyhum.JumpHeight = 7.2
hit.Parent.Values.Stunned.Value = false
end
end
end
end)
hitbox.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and activated == true and PlayersHit2[hit.Parent] == nil then
if hit.Parent.Values.Iframes.Value == false and hit.Parent ~= plr.Character then
PlayersHit2[hit.Parent] = true
local enemy = hit.Parent
local enemyhum = enemy:WaitForChild("Humanoid")
enemyhum.WalkSpeed = 1
enemyhum.JumpHeight = 1
local ui = StunnedGui:Clone()
ui.Parent = hit.Parent.Head
game.Debris:AddItem(ui, .2)
hit.Parent.Values.Stunned.Value = true
enemy:WaitForChild("Humanoid"):TakeDamage(damage)
enemy.HumanoidRootPart.CFrame = CFrame.lookAt(hit.Parent.HumanoidRootPart.Position, plr.Character.HumanoidRootPart.Position)
local track2 = enemyhum:LoadAnimation(LeftHit)
track2:Play()
local BloodEffect = RS.Effects:WaitForChild("Blood").Attachment:Clone()
BloodEffect.Parent = enemy.HumanoidRootPart
game:GetService("Debris"):AddItem(BloodEffect,1)
local HitEffect = RS.Effects:WaitForChild("Hit").Attachment:Clone()
HitEffect.Parent = enemy.HumanoidRootPart
HitEffect.ParticleEmitter:Emit(10)
game:GetService("Debris"):AddItem(HitEffect,1)
local PunchSound = script.Punch:Clone()
PunchSound.Parent = plr.Character.HumanoidRootPart
PunchSound:Play()
game:GetService("Debris"):AddItem(PunchSound,.6)
local vel = Instance.new("BodyVelocity", hit.Parent.HumanoidRootPart)
vel.MaxForce = Vector3.new(1,1,1) * 1000000;
vel.Parent = hit.Parent.HumanoidRootPart
vel.Velocity = Vector3.new(1,1,1) * plr.Character:WaitForChild("HumanoidRootPart").CFrame.LookVector * pushForce
vel.Name = "SmallMoveVel"
game.Debris:AddItem(vel,0.4)
local highlight = Instance.new("Highlight")
highlight.Parent = enemy
highlight.DepthMode = Enum.HighlightDepthMode.Occluded
highlight.FillTransparency = 0
highlight.OutlineTransparency = 1
game:GetService("TweenService"):Create(highlight, TweenInfo.new(1, Enum.EasingStyle.Linear, Enum.EasingDirection.Out, 0, true), {FillTransparency = 1}):Play()
game.Debris:AddItem(highlight, 1)
if plr:WaitForChild("RageValues").Ultimate.Value == false then
plr:WaitForChild("RageValues").RageValue.Value += damage / 2
end
local EnemyScript = script.EnemyScript:Clone()
EnemyScript.Parent = enemy
EnemyScript.Disabled = false
game.Debris:AddItem(EnemyScript,1)
task.wait(.2)
PlayersHit2[hit.Parent] = nil
task.wait(.3)
if enemy.Values.Stunned.Value == true then
enemyhum.WalkSpeed = 16
enemyhum.JumpHeight = 7.2
hit.Parent.Values.Stunned.Value = false
end
end
end
end)
task.wait(3)
hitbox:Destroy()
PunchSwingSound:Stop()
plr.Character.Humanoid.WalkSpeed = 16
activated = false
Trail.Enabled = false
Trail2.Enabled = false
task.wait(1)
Trail:Destroy()
Trail2:Destroy()
end)
Does someone know how to improve that?