Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Explanation: This ServerScript runs through a local script inserted into a tool named "Combat.", which fires off a remote event that triggers said server script. The local script itself has 3 values it may pass on when firing the remote event, which are either: "Normal", which is any attack with a comboCount less than 4, and "Final" which is any attack with a comboCount >= 4, and "Black Flash" which is a 1 in 40 chance of a special attack. There will be a provided tool named "Black Flash" which will have it occur on every use. Now here is the serverscript, which is approximately 223 lines of code.
-
- -- Blocking Explanation: Before we get into the serverscript, there is a seperate local script that is placed into startercharacter scripts, where if the player presses "F" (or a button on mobile), they will fire off a remote event to change a boolValue also in startercharacterscripts to true. Now here is the serverscript.
-
-
- -- // Remote Event Declaration \\
-
- local remote = game.ReplicatedStorage.Remotes.CombatRemote
-
-
-
- remote.OnServerEvent:Connect(function(plr, state) -- state is what the LocalScript passed on, which could either be a block, or a combo type.
- -- // Variables \\
- local char = plr.Character
- local hum = char:WaitForChild("Humanoid")
- local humrp = char:WaitForChild("HumanoidRootPart")
- -- // Blocking Remotes \\
- if state == "BlockStart" then
- char:WaitForChild("Blocking").Value = true -- sets Blocking boolValue to true
- end
- if state == "BlockEnd" then
- char:WaitForChild("Blocking").Value = false -- sets Blocking boolValue to false
- end
- -- // Normal Combo \\
- if state == "Normal" then
- -- Hitbox creation with it's properties, and moving it infront of the player using CFrames.
- local hitbox = Instance.new("Part", workspace)
- hitbox.CFrame = humrp.CFrame * CFrame.new(0, 0, -2.5)
- hitbox.Size = Vector3.new(5, 5, 5)
- hitbox.Transparency = 0.5
- hitbox.BrickColor = BrickColor.Green()
- hitbox.CanCollide = false
- hitbox.Anchored = false
- game.Debris:AddItem(hitbox, 0.35)
- -- Welding the Hitbox to the player, since if it is anchored, it will lead to inaccurate Combat
- local weld = Instance.new("WeldConstraint")
- weld.Parent = hitbox
- weld.Part0 = humrp
- weld.Part1 = hitbox
- -- Handles the removal of the hitbox after enough time passes using Debris Service.
- game.Debris:AddItem(weld, 0.35)
- local Hits = {} -- Table of everything hit, used in the hitbox.Touched event to ensure noone gets damaged twice.
- -- // Hitbox Touched \\
- hitbox.Touched:Connect(function(hit)
- if hit.Parent:FindFirstChild("Humanoid") then -- Checking if the parent of the hit is a Humanoid
- if hit.Name == "HumanoidRootPart" then -- Checking if the hit part is a HumanoidRootPart
- if hit.Parent.Name ~= char.Name then -- Ensuring the hit part is not the player
- if Hits[hit.Parent.Name] then
- return
- end -- If the target has already been hit once, then this will return.
- if hit.Parent:FindFirstChild("Blocking").Value == true then
- local hitSfx = game.SoundService.Block:Clone()
- hitSfx.Parent = hit.Parent
- hitSfx:Play()
- game.Debris:AddItem(hitSfx, 0.4)
- return
- end -- If it's true, then the next portion of the script is negated due to this if statement returning, it also plays a block sound effect.
- Hits[hit.Parent.Name] = true
- local ehum = hit.Parent:WaitForChild("Humanoid")
- ehum:TakeDamage(3) -- Damages the player and sets their damaged status to true.
- local track = game.SoundService.Hit:Clone()
- track.Parent = hit.Parent
- track:Play()
- game.Debris:AddItem(track, 0.7)
- -- Plays hit sfx
- wait(0.2)
- local anim = ehum:LoadAnimation(game.ReplicatedStorage.Animations.Combat.Hit)
- anim:Play()
- Hits[hit.Parent.Name] = false -- Plays animation of player getting hit, and disables the hit status of the target.
- end
- end
- end
- end)
- end
- -- // Final Hit in a Comboo \\
- if state == "Final" then
- local hitbox = Instance.new("Part", workspace)
- hitbox.CFrame = humrp.CFrame * CFrame.new(0, 0, -2.5)
- hitbox.Size = Vector3.new(5, 5, 5)
- hitbox.Transparency = 0.5
- hitbox.BrickColor = BrickColor.Red()
- hitbox.CanCollide = false
- hitbox.Anchored = false
- game.Debris:AddItem(hitbox, 0.35)
-
- local weld = Instance.new("WeldConstraint")
- weld.Parent = hitbox
- weld.Part0 = humrp
- weld.Part1 = hitbox
-
- game.Debris:AddItem(weld, 0.35)
- local Hits = {}
-
- hitbox.Touched:Connect(function(hit)
- if hit.Parent:FindFirstChild("Humanoid") then
- if hit.Name == "HumanoidRootPart" then
- if hit.Parent.Name ~= char.Name then
- if Hits[hit.Parent.Name] then
- return
- end
- if hit.Parent:WaitForChild("Blocking").Value == true then
- local hitSfx = game.SoundService.BlockBreak:Clone()
- local ehum = hit.Parent:WaitForChild("Humanoid")
- hitSfx.Parent = hit.Parent
- hitSfx:Play()
- game.Debris:AddItem(hitSfx, 0.4)
-
- hit.Parent:WaitForChild("Stunned").Value = true
- ehum.WalkSpeed = 0
- end -- This time, however, rather than return, the script instead plays the sfx of breaking the block, and stuns the enemy,
- Hits[hit.Parent.Name] = true
- local ehum = hit.Parent:WaitForChild("Humanoid")
- local ehumrp = hit.Parent:WaitForChild("HumanoidRootPart")
- ehum:TakeDamage(6) -- More damage on final hit
- local bv = Instance.new("BodyVelocity", ehumrp)
- bv.MaxForce = Vector3.one * math.huge
- bv.Velocity = char.HumanoidRootPart.CFrame.LookVector * 35 + Vector3.new(0, 45, 0)
- game.Debris:AddItem(bv, 0.12) -- Uses body velocity to knockback the target
-
- local track = game.SoundService.HitCrit:Clone()
- track.Parent = hit.Parent
- track:Play()
- game.Debris:AddItem(track, 0.7)
-
- wait(0.2)
- local anim = ehum:LoadAnimation(game.ReplicatedStorage.Animations.Combat.Knockback)
- anim:Play()
- ehum.WalkSpeed = 16
- hit.Parent:WaitForChild("Stunned").Value = false
- Hits[hit.Parent.Name] = false -- Unstuns the opponent, and plays a knockback animation.
- end
- end
- end
- end)
- end
- -- // Black Flash (1 in 40 chance) \\
- if state == "BlackFlash" then
- print("Black Flash!")
- local bf = game.ReplicatedStorage.Models.HandFlash:Clone()
- bf.Anchored = false
- bf.Parent = char
- bf.CFrame = humrp.CFrame
- game.Debris:AddItem(bf, 2)
-
- local weld2 = Instance.new("WeldConstraint")
- weld2.Parent = bf
- weld2.Part0 = humrp
- weld2.Part1 = bf
- -- Welds the BlackFlash model intended to be used for the char to the char's root part.
- game.Debris:AddItem(weld2, 2)
- local hitbox = Instance.new("Part", workspace)
- hitbox.CFrame = humrp.CFrame * CFrame.new(0, 0, -2.5)
- hitbox.Size = Vector3.new(5, 5, 5)
- hitbox.Transparency = 0.5
- hitbox.BrickColor = BrickColor.Black()
- hitbox.CanCollide = false
- hitbox.Anchored = false
- game.Debris:AddItem(hitbox, 0.35)
-
- local weld = Instance.new("WeldConstraint")
- weld.Parent = hitbox
- weld.Part0 = humrp
- weld.Part1 = hitbox
-
- game.Debris:AddItem(weld, 0.35)
- local Hits = {}
-
- hitbox.Touched:Connect(function(hit)
- if hit.Parent:FindFirstChild("Humanoid") then
- if hit.Name == "HumanoidRootPart" then
- if hit.Parent.Name ~= char.Name then
- if Hits[hit.Parent.Name] then
- return
- end
- if hit.Parent:WaitForChild("Blocking").Value == true then
- local hitSfx = game.SoundService.BlockBreak:Clone()
- local ehum = hit.Parent:WaitForChild("Humanoid")
- hitSfx.Parent = hit.Parent
- hitSfx:Play()
- game.Debris:AddItem(hitSfx, 0.4)
-
- hit.Parent:WaitForChild("Stunned").Value = true
- ehum.WalkSpeed = 0
- end
- Hits[hit.Parent.Name] = true
- local ehum = hit.Parent:WaitForChild("Humanoid")
- local ehumrp = hit.Parent:WaitForChild("HumanoidRootPart")
- ehum:TakeDamage(9) -- Increased damage here a swell.
- local bf = game.ReplicatedStorage.Models.BlackFlash:Clone()
- bf.Anchored = false
- bf.Parent = hit.Parent
- bf.CFrame = ehumrp.CFrame
- game.Debris:AddItem(bf, 2)
-
- local weld2 = Instance.new("WeldConstraint")
- weld2.Parent = bf
- weld2.Part0 = ehumrp
- weld2.Part1 = bf
- -- Welds the BlackFlash model intended to be added to the opponent
- game.Debris:AddItem(weld2, 2)
-
- local bv = Instance.new("BodyVelocity", ehumrp)
- bv.MaxForce = Vector3.one * math.huge
- bv.Velocity = char.HumanoidRootPart.CFrame.LookVector * 35 + Vector3.new(0, 45, 0)
- game.Debris:AddItem(bv, 0.12)
-
- local track = game.SoundService.HitCrit:Clone()
- track.Parent = hit.Parent
- track:Play()
- game.Debris:AddItem(track, 0.7)
-
- wait(0.2)
- ehum.WalkSpeed = 16
- hit.Parent:WaitForChild("Stunned").Value = false
- local anim = ehum:LoadAnimation(game.ReplicatedStorage.Animations.Combat.Knockback)
- anim:Play()
- Hits[hit.Parent.Name] = false
- end
- end
- end
- end)
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement