Advertisement
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
- --[[
- Animation 1 = Underhand
- Animation 2 = Overhand
- ]]--
- local OnCooldown = false
- HitBox.OnHit:Connect(function(hit, humanoid)
- if hit.Parent.Name == Player.Name then return end
- if hit.Parent.Humanoid then
- if game.Players:FindFirstChild(hit.Parent.Name) then
- warn(hit.Parent.Name)
- local playerPlr = game.Players:FindFirstChild(hit.Parent.Name)
- if playerPlr.isBlocking.Value == 'Yes' then
- humanoid:TakeDamage(BlockDamage.Value)
- cloneBlood(hit.Parent.HumanoidRootPart)
- -- Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
- -- KnockForward(Player.Character.HumanoidRootPart)
- elseif playerPlr.isBlocking.Value == 'No' or playerPlr.isBlocking.Value == 'None' then
- humanoid:TakeDamage(Damage.Value)
- cloneBlood(hit.Parent.HumanoidRootPart)
- Knockback(hit.Parent.HumanoidRootPart, Player.Character.HumanoidRootPart)
- KnockForward(Player.Character.HumanoidRootPart)
- 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)
- end
- end
- -- Add hit animation to player.
- 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.
- OnCooldown = true
- LoadAnimation(game.Workspace[Player.Name], Animations[AnimationOn])
- warn(AnimationOn)
- HitBox:HitStart()
- wait(1)
- 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 = '1'
- warn(AnimationOn)
- end
- end)
- Ev.OnServerEvent:Connect(function(plr, action)
- if action == 'UnEquip' then
- local char = plr.Character
- local copy = Storage:WaitForChild("SwordCopy"):Clone()
- copy.Parent = char
- copy.GripWeld.Part1 = char.UpperTorso
- copy.GripWeld.C0 = CFrame.new(-1.12,-1.02,1)
- copy.GripWeld.C0 = copy.GripWeld.C0 * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(-165),-20.5)
- end
- if action == 'Equip' then
- plr.Character:FindFirstChild('SwordCopy'):Destroy()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement