Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Sword Server Script
- -- By Sylvern
- -- 4/19/2020
- --[[
- Add animations when received.
- Animations switch are Underhand and Overhand.
- ]] --
- local Player =
- script:FindFirstAncestorWhichIsA("Player") or
- game:GetService("Players"):GetPlayerFromCharacter(script.Parent.Parent)
- local Players = game:GetService("Players")
- local Debris = game:GetService("Debris")
- local Storage = game:GetService("ReplicatedStorage")
- local Tool = script.Parent
- local Handle = Tool:WaitForChild("Handle")
- local Animations = Tool:WaitForChild("Animations")
- local Particle = Storage:WaitForChild("ParticleEmitter")
- local Configuration = Tool:WaitForChild("Configuration")
- local Damage = Configuration:WaitForChild("Damage")
- local BlockDamage = Configuration:WaitForChild("BlockDamage")
- local Event = script.Parent:WaitForChild("ChangeAnimation")
- local Cooldown = 0.3
- local RaycastHitBox = require(Tool:WaitForChild("RaycastHitbox"))
- local HitBox = RaycastHitBox:Initialize(Handle)
- local Ev = Tool:WaitForChild("Weld")
- local AnimationOn = "1" -- underhand
- local Sounds = Tool:WaitForChild("Sounds")
- --
- --[[
- Animation 1 = Underhand
- Animation 2 = Overhand
- ]] local OnCooldown = false
- function playSound(sound)
- sound:Play()
- end
- HitBox.OnHit:Connect(
- function(hit, humanoid)
- if hit.Parent.Name == Player.Name then
- return
- end
- if hit.Parent.Humanoid then
- local Facing = hit.Parent.HumanoidRootPart.CFrame.LookVector
- local Vector = (Player.Character.HumanoidRootPart.Position - hit.Parent.HumanoidRootPart.Position).unit
- local Angle = math.acos(Facing:Dot(Vector))
- -- warn(Angle) -- 0.2 or 2
- if game.Players:FindFirstChild(hit.Parent.Name) then
- -- warn(hit.Parent.Name)
- local playerPlr = game.Players:FindFirstChild(hit.Parent.Name)
- if playerPlr.onBack.Value == true and Angle >= 2 and playerPlr.isBlocking.Value == 'No' or playerPlr.isBlocking.Value == 'None' then
- warn "Shield is on back. Cant attack."
- playSound(Sounds:WaitForChild('ShieldHit'))
- return
- end
- if playerPlr.isBlocking.Value == "Yes" and Angle >= 2 then
- humanoid:TakeDamage(Damage.Value)
- cloneBlood(hit.Parent.HumanoidRootPart)
- Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
- KnockForward(Player.Character.HumanoidRootPart)
- playSound(Sounds:WaitForChild("Hit"))
- -- warn("what is minecraft...")
- return
- end
- if playerPlr.isBlocking.Value == "Yes" and Angle <= 1 then
- -- humanoid:TakeDamage(BlockDamage.Value)
- -- cloneBlood(hit.Parent.HumanoidRootPart)
- playSound(Sounds:WaitForChild("ShieldHit"))
- reduceStamina(playerPlr)
- -- Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
- -- KnockForward(Player.Character.HumanoidRootPart)
- -- warn("what is my life")
- -- stopHit(playerPlr)
- return
- end
- if playerPlr.isBlocking.Value == "No" or "None" then
- humanoid:TakeDamage(Damage.Value)
- cloneBlood(hit.Parent.HumanoidRootPart)
- Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
- -- KnockForward(Player.Character.HumanoidRootPart)
- playSound(Sounds:WaitForChild("Hit"))
- return
- end
- else
- -- warn(hit.Parent.Name)
- Slowness(hit.Parent.HumanoidRootPart)
- cloneBlood(hit.Parent.HumanoidRootPart)
- Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
- -- KnockForward(Player.Character.HumanoidRootPart)
- hit.Parent.Humanoid:TakeDamage(Damage.Value)
- playSound(Sounds:WaitForChild("Hit"))
- return
- end
- end
- -- Add hit animation to player.
- end
- )
- function stopHit(plr)
- plr:WaitForChild('CanHit').Value = false
- wait(2)
- plr:WaitForChild('CanHit').Value = true
- end
- function reduceStamina(plrModel)
- local shieldStrength = plrModel:FindFirstChild("ShieldStrength")
- if shieldStrength then
- shieldStrength.Value = shieldStrength.Value - 30
- end
- end
- function cloneBlood(plrModel)
- local Clone = Particle:Clone()
- Clone.Parent = plrModel
- Debris:AddItem(Clone, 0.8)
- end
- function Slowness(plrModel)
- local BV = Instance.new("BodyVelocity", plrModel)
- BV.Name = "Slowness"
- BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- BV.P = 2000
- BV.Velocity = Vector3.new(0, 0, 0)
- Debris:AddItem(BV, 0.2)
- end
- function KnockForward(plrModel)
- local BV = Instance.new("BodyVelocity", plrModel)
- BV.Name = "Knockback"
- BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- BV.P = 2000
- BV.Velocity = plrModel.CFrame.lookVector * 15
- Debris:AddItem(BV, 0.2)
- end
- function Knockback(plrModel, plrAttacking)
- local BV = Instance.new("BodyVelocity", plrModel)
- BV.Name = "Knockback"
- BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- -- BV.P = 2000
- BV.Velocity = plrAttacking.CFrame.lookVector * 18
- Debris:AddItem(BV, 0.2)
- end
- function LoadAnimation(plrModel, animation)
- local Animation = plrModel.Humanoid:LoadAnimation(animation)
- Animation:Play()
- end
- Tool.Activated:Connect(
- function()
- if OnCooldown then
- return
- end -- Debounce cooldown.
- if Player:WaitForChild('CanHit').Value == false then
- return
- end -- Can hit check.
- OnCooldown = true
- LoadAnimation(game.Workspace[Player.Name], Animations[AnimationOn])
- playSound(Sounds:WaitForChild("Swing"))
- warn(AnimationOn)
- HitBox:HitStart()
- wait(0.8)
- HitBox:HitStop()
- wait(Cooldown)
- OnCooldown = false
- -- Play animation.
- end
- )
- Event.OnServerEvent:Connect(
- function(plr) -- 1 is underhand and 2 is overhand
- if AnimationOn == "1" then
- AnimationOn = "2"
- warn(AnimationOn)
- elseif AnimationOn == "2" then
- AnimationOn = "3"
- warn(AnimationOn)
- elseif AnimationOn == "3" then
- AnimationOn = "1"
- warn(AnimationOn)
- end
- end
- )
- Ev.OnServerEvent:Connect(
- function(plr, action)
- if action == "UnEquip" then
- LoadAnimation(game.Workspace[plr.Name], Tool:WaitForChild("UnEquip"))
- -- wait(0.5)
- local char = plr.Character
- local copy = Storage:WaitForChild("SwordCopy"):Clone()
- copy.Parent = char
- copy.UpperTorso.Part1 = char.UpperTorso
- end
- if action == "Equip" then
- plr.Character:FindFirstChild("SwordCopy"):Destroy()
- LoadAnimation(game.Workspace[plr.Name], Tool:WaitForChild("Equip"))
- end
- end
- )
Advertisement
Add Comment
Please, Sign In to add comment