Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ~~~~~~~~~~~~~~~~~
- game.Players.PlayerAdded:connect(function(playerr)
- script.Parent.OnServerEvent:connect(function(plr,d)
- repeat wait() until plr.Character
- local character = plr.Character
- local mouse = d
- local tool = plr.Backpack.Lightsaber
- local ls = "LightSaberModel"
- -------------------------------------------------------------------------------------
- local poseanim = Instance.new("Animation")
- poseanim.AnimationId = "rbxassetid://579218292"
- local pose = character.Humanoid:LoadAnimation(poseanim)
- local equipanim = Instance.new("Animation")
- equipanim.AnimationId = "rbxassetid://579218986"
- local equip = character.Humanoid:LoadAnimation(equipanim)
- local block1anim = Instance.new("Animation")
- block1anim.AnimationId = "rbxassetid://579216931"
- local block1 = character.Humanoid:LoadAnimation(block1anim)
- local stunanim = Instance.new("Animation")
- stunanim.AnimationId = "rbxassetid://579218986"
- local stun = character.Humanoid:LoadAnimation(stunanim)
- -------------------------------------------------------------------------------------
- local enabled = false
- local active = false
- local activating = false
- local attacking = false
- local canattack = false
- local candamage = false
- local jumping = false
- local forceactive = false
- local blocking = false
- local canblock = false
- local timer = 0
- local direction = 0
- local hitcounter = 0
- local stamina = 200
- -------------------------------------------------------------------------------------
- function UpdateStamina()
- if stamina <= 0 and character:FindFirstChild(ls) and active then
- attacking = false
- candamage = false
- canattack = false
- if character.Humanoid:FindFirstChild("Block") then
- character.Humanoid:FindFirstChild("Block"):Remove()
- end
- block1:Stop()
- local saber = character:FindFirstChild(ls)
- saber.Blade.CanClash.Value = false
- local sound = saber.Blade:FindFirstChild("slash")
- sound.Pitch = math.random(95,110)/100
- sound:Play()
- blocking = false
- canattack = true
- canblock = true
- end
- while (blocking == false and enabled and stamina < 200) and character:FindFirstChild(ls) do
- stamina = stamina + 2
- wait()
- end
- end
- function WeldParts(b)
- local saber = game.Lighting:FindFirstChild(ls):Clone()
- saber.Parent = character
- local a = saber.Handle
- local w = Instance.new("Weld")
- w.Name = "SaberWeld"
- w.Parent = a
- w.Part0 = b
- w.Part1 = a
- w.C0 = CFrame.new(0,-1,0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(180),math.rad(180))
- end
- function OnTouch(p)
- if candamage == true then
- local mySaber = character:FindFirstChild(ls)
- local theirSaber = p.Parent.Parent:FindFirstChild(ls)
- if (p.Name == "Blade" or p.Name == "Blade2") then
- if p:FindFirstChild("CanClash").Value == true then
- local function AddEffect(name,parent,duration)
- local effect = game.ReplicatedStorage[name]:Clone()
- effect.Parent = parent
- game.Debris:AddItem(effect,duration)
- end
- candamage = false
- local SoundList = {"hit1","hit2"}
- local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
- sound.Pitch = math.random(90,110)/100
- sound:Play()
- AddEffect("Clash",mySaber.Blade,0.2)
- AddEffect("Sparks",theirSaber.Blade,0.75)
- AddEffect("ClashLight",theirSaber.Aura,0.4)
- if theirSaber:FindFirstChild("Blade2") then
- AddEffect("Sparks",theirSaber.Blade2,0.75)
- AddEffect("ClashLight",theirSaber.Aura2,0,4)
- end
- if theirSaber.Parent.Humanoid:FindFirstChild("Block") then
- theirSaber.Parent.Humanoid:FindFirstChild("Block"):Remove()
- local signal = Instance.new("ObjectValue")
- signal.Name = "ClashSignal"
- signal.Parent = theirSaber.Parent.Humanoid
- Stun()
- end
- end
- elseif p.Name == "Torso" and p.Parent:FindFirstChild("Humanoid") then
- candamage = false
- local hum = p.Parent:FindFirstChild("Humanoid")
- if not hum:FindFirstChild("Block") then
- hum:TakeDamage(21)
- local SoundList = {"hit1","hit2"}
- local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
- sound.Pitch = math.random(90,110)/100
- sound:Play()
- elseif hum:FindFirstChild("Block") then
- hum:TakeDamage(0)
- end
- if not p.Parent:FindFirstChild(ls) then
- hum:TakeDamage(55)
- end
- elseif (p.Name == "Left Arm"
- or p.Name == "Right Arm"
- or p.Name == "Right Leg"
- or p.Name == "Left Leg"
- or p.Name == "Head")
- and p.Parent:FindFirstChild("Humanoid") then
- if p.Parent:FindFirstChild(ls) then
- local num = math.random(1,85)
- if num == 1 then
- candamage = false
- local hum = p.Parent:FindFirstChild("Humanoid")
- if not hum:FindFirstChild("Block") then
- hum:TakeDamage(21)
- local SoundList = {"hit1","hit2"}
- local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
- sound.Pitch = math.random(90,110)/100
- sound:Play()
- p:BreakJoints()
- p.CanCollide = true
- p.Anchored = false
- local Sounds = {"rbxassetid://337800380","rbxassetid://337804646"}
- local s = Instance.new("Sound")
- s.Parent = p.Parent.Head
- s.SoundId = Sounds[math.random(1,2)]
- s.Volume = 1
- s.Pitch = 1
- s.Looped = false
- local w = Instance.new("Weld")
- w.Parent = mySaber.Aura
- w.Part0 = w.Parent
- w.Part1 = p
- game.Debris:AddItem(s,3)
- s:Play()
- game.Debris:AddItem(w,0.3)
- end
- end
- elseif not p.Parent:FindFirstChild(ls) then
- candamage = false
- local hum = p.Parent:FindFirstChild("Humanoid")
- if not hum:FindFirstChild("Block") then
- hum:TakeDamage(21)
- local SoundList = {"hit1","hit2"}
- local sound = mySaber.Blade:FindFirstChild(SoundList[math.random(1,2)])
- sound.Pitch = math.random(90,110)/100
- sound:Play()
- p:BreakJoints()
- p.CanCollide = true
- p.Anchored = false
- local Sounds = {"rbxassetid://337800380","rbxassetid://337804646"}
- local s = Instance.new("Sound")
- s.Parent = p.Parent.Head
- s.SoundId = Sounds[math.random(1,2)]
- s.Volume = 1
- s.Pitch = 1
- s.Looped = false
- local w = Instance.new("Weld")
- w.Parent = mySaber.Aura
- w.Part0 = w.Parent
- w.Part1 = p
- game.Debris:AddItem(s,3)
- s:Play()
- game.Debris:AddItem(w,0.3)
- end
- end
- end
- end
- end
- function Selected()
- enabled = true
- equip:Play(0.1,1,1.6)
- stamina = 200
- if not character:FindFirstChild(ls) then
- WeldParts(character["Right Arm"])
- end
- if character:FindFirstChild("HipSaber") then
- character:FindFirstChild("HipSaber"):Remove()
- end
- local saber = character:FindFirstChild(ls)
- saber.Handle.Equip:Play()
- saber.Aura.Glow.Color = tool.Glow.Value
- local c = saber.Emitter:GetChildren()
- for i = 1,#c do
- if c[i]:IsA("ParticleEmitter") then
- c[i].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
- end
- end
- local c = saber.Aura:GetChildren()
- for i = 1,#c do
- if c[i]:IsA("ParticleEmitter") then
- c[i].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
- end
- character:FindFirstChild(ls).Blade.Touched:connect(OnTouch)end
- mouse.Button2Up:connect(Button2Up)
- end
- function Deselected()
- if active == true then
- character[ls].Handle.sheathe:Play()
- end
- stamina = 200
- character.Humanoid.WalkSpeed = 16
- enabled = false
- active = false
- attacking = false
- canattack = false
- candamage = false
- blocking = false
- canblock = false
- blocking = false
- pose:Stop()
- block1:Stop()
- if character:FindFirstChild(ls) then
- character[ls]:Remove()
- end
- if character.Humanoid:FindFirstChild("Block") then
- character.Humanoid:FindFirstChild("Block"):Remove()
- end
- if not character:FindFirstChild("HipSaber") then
- local hilt = game.Lighting.LightSaberModel:Clone()
- hilt.Parent = character
- hilt.Name = "HipSaber"
- local a = hilt.Handle
- local w = Instance.new("Weld")
- w.Name = "Weld"
- w.Parent = a
- w.Part0 = character["Torso"]
- w.Part1 = a
- w.C0 = CFrame.new(-0.8,-1,-0.6) * CFrame.fromEulerAnglesXYZ(math.rad(180),math.rad(180),math.rad(-5))
- end
- end
- mouse.Button1Down:connect(function()
- local SwingSounds = {"slash","slash2"}
- if (enabled and active) and canattack and blocking == false and forceactive == false then
- local saber = character:FindFirstChild(ls)
- if saber.Blade.CanClash.Value == false then
- coroutine.resume(coroutine.create(function()
- local c = saber.Blade:GetChildren()
- for n = 1,#c do
- if c[n]:IsA("ParticleEmitter") then
- c[n].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
- c[n].Enabled = true
- end
- end
- end))
- attacking = true
- canblock = false
- canattack = false
- local sound = saber.Blade:FindFirstChild(SwingSounds[math.random(1,2)])
- sound.Pitch = math.random(100,110)/100
- sound:Play()
- local function GetAnimation()
- local slashanims = {"Attack1","Attack2"}
- if hitcounter == 0 then
- timer = tick()
- hitcounter = 1
- return slashanims[1]
- elseif hitcounter == 1 then
- if (tick() - timer) > 1 then
- timer = tick()
- hitcounter = 1
- return slashanims[1]
- elseif (tick() - timer) < 1 then
- hitcounter = 0
- return slashanims[2]
- end
- end
- end
- local track = GetAnimation()
- local slash = character.Humanoid:LoadAnimation(tool[track])
- slash:Play(0.1,1,1.7)
- candamage = true
- saber.Blade.CanClash.Value = true
- character.Humanoid.WalkSpeed = 22
- wait(0.6)
- coroutine.resume(coroutine.create(function()
- local c = saber.Blade:GetChildren()
- for n = 1,#c do
- if c[n]:IsA("ParticleEmitter") then
- c[n].Color = ColorSequence.new(tool.Glow.Value,tool.Glow.Value)
- c[n].Enabled = false
- end
- end
- end))
- candamage = false
- character.Humanoid.WalkSpeed = 16
- saber.Blade.CanClash.Value = false
- wait(0.15)
- attacking = false
- canattack = true
- canblock = true
- end
- end
- end)
- mouse.Button2Down:connect(function()
- if (enabled and active and stamina > 0) and canblock == true and forceactive == false then
- blocking = true
- if not character.Humanoid:FindFirstChild("Block") then
- local blocker = Instance.new("ObjectValue")
- blocker.Name = "Block"
- blocker.Parent = character.Humanoid
- end
- attacking = false
- candamage = false
- canattack = false
- block1:Play()
- local saber = character:FindFirstChild(ls)
- saber.Blade.CanClash.Value = true
- local sound = saber.Blade:FindFirstChild("slash")
- sound.Pitch = math.random(95,110)/100
- sound:Play()
- Blocking()
- elseif (enabled and active and stamina > 0) and attacking and forceactive == false then
- blocking = true
- canblock = true
- if not character.Humanoid:FindFirstChild("Block") then
- local blocker = Instance.new("ObjectValue")
- blocker.Name = "Block"
- blocker.Parent = character.Humanoid
- end
- attacking = false
- canattack = false
- block1:Play()
- local saber = character:FindFirstChild(ls)
- saber.Blade.CanClash.Value = true
- local sound = saber.Blade:FindFirstChild("slash")
- sound.Pitch = math.random(95,110)/100
- sound:Play()
- Blocking()
- end
- end)
- function Button2Up()
- if enabled and active and blocking and forceactive == false then
- if character.Humanoid:FindFirstChild("Block") then
- character.Humanoid:FindFirstChild("Block"):Remove()
- end
- block1:Stop()
- local saber = character:FindFirstChild(ls)
- saber.Blade.CanClash.Value = false
- local sound = saber.Blade:FindFirstChild("slash")
- sound.Pitch = math.random(95,110)/100
- sound:Play()
- wait()
- canattack = true
- canblock = true
- blocking = false
- coroutine.resume(coroutine.create(UpdateStamina))
- end
- end
- function Stun()
- local saber = character:FindFirstChild(ls)
- pose:Stop()
- block1:Stop()
- stun:Play(0.5,1,1)
- character.Humanoid.WalkSpeed = 0
- character.Humanoid.JumpPower = 0
- if character.Humanoid:FindFirstChild("Block") then
- character.Humanoid:FindFirstChild("Block"):Remove()
- end
- enabled = false
- attacking = false
- canattack = false
- candamage = false
- blocking = false
- canblock = false
- blocking = false
- jumping = true
- wait(0.75)
- character.Humanoid.WalkSpeed = 16
- character.Humanoid.JumpPower = 50
- stun:Stop()
- pose:Play()
- jumping = false
- enabled = true
- canattack = true
- canblock = true
- end
- function BladeUp()
- local saber = character:findFirstChild(ls)
- saber.Emitter.EmitterWeld.C0 = CFrame.new(0,0,0)
- local c = saber.Emitter:GetChildren()
- for i = 1,#c do
- if c[i]:IsA("ParticleEmitter") then
- c[i].Enabled = true
- end
- end
- saber.Aura.Transparency = 0.01
- local m = Instance.new("CylinderMesh")
- m.Parent = saber.Aura
- m.Scale = Vector3.new(1,0,1)
- m.Offset = Vector3.new(0,-2.05,0)
- local x = 15
- for i = 1,x do
- m.Scale = m.Scale + Vector3.new(0,1/x,0)
- m.Offset = m.Offset + Vector3.new(0,2.05/x)
- wait()
- end
- m:Destroy()
- local c = saber.Aura:GetChildren()
- for i = 1,#c do
- if c[i]:IsA("ParticleEmitter") then
- c[i].Transparency = NumberSequence.new(0.95)
- end
- end
- end
- function BladeDown()
- local saber = character:findFirstChild(ls)
- saber.Emitter.EmitterWeld.C0 = CFrame.new(0,4.15,0)*CFrame.fromEulerAnglesXYZ(0,0,math.rad(180))
- wait(0.2)
- local m = Instance.new("CylinderMesh")
- m.Parent = saber.Aura
- m.Scale = Vector3.new(1,1,1)
- m.Offset = Vector3.new(0,0,0)
- local c = saber.Emitter:GetChildren()
- for i = 1,#c do
- if c[i]:IsA("ParticleEmitter") then
- c[i].Enabled = false
- end
- end
- local c = saber.Aura:GetChildren()
- for i = 1,#c do
- if c[i]:IsA("ParticleEmitter") then
- c[i].Transparency = NumberSequence.new(1)
- end
- end
- local x = 13
- for i = 1,x do
- m.Scale = m.Scale - Vector3.new(0,1/x,0)
- m.Offset = m.Offset - Vector3.new(0,2.05/x)
- wait()
- end
- m:Destroy()
- saber.Aura.Transparency = 1
- end
- mouse.KeyDown:connect(function(key)
- --Toggling
- local saber = character:FindFirstChild(ls)
- if key == "q" and enabled then
- if active == false and activating == false and not blocking and not attacking then
- activating = true
- active = true
- pose:Play()
- wait(0.2)
- saber.Aura.Glow.Enabled = true
- saber.Handle.ignite:Play()
- saber.Handle.loop:Play()
- attacking = false
- canattack = true
- candamage = false
- blocking = false
- canblock = true
- BladeUp()
- activating = false
- elseif active == true and activating == false and not blocking and not attacking then
- activating = true
- active = false
- saber.Handle.sheathe:Play()
- BladeDown()
- saber.Aura.Glow.Enabled = false
- saber.Handle.loop:Pause()
- wait(0.2)
- pose:Stop()
- block1:Stop()
- activating = false
- attacking = false
- canattack = false
- candamage = false
- blocking = false
- canblock = false
- if character.Humanoid:FindFirstChild("Block") then
- character.Humanoid:FindFirstChild("Block"):Remove()
- end
- end
- --Flips
- elseif (key == "2"
- and jumping == false
- and blocking == false
- and direction ~= 0) then
- local function Flip()
- local flips = {579217547,0,579216033,0}
- local fliptrack = Instance.new("Animation")
- fliptrack.AnimationId = "rbxassetid://"..flips[direction]
- local flip = character.Humanoid:LoadAnimation(fliptrack)
- character.Humanoid.JumpPower = 65
- character.Humanoid.Jump = true
- character.Humanoid.WalkSpeed = 40
- stun:Stop()
- flip:Play(0.1,1,1.3)
- jumping = true
- canblock = false
- candamage = false
- attacking = false
- wait(0.4)
- character.Humanoid.WalkSpeed = 16
- character.Humanoid.JumpPower = 50
- canblock = true
- wait(0.7)
- jumping = false
- end
- if direction == 1 or direction == 3 then
- Flip()
- end
- elseif key == "w" then
- direction = 1
- elseif key == "s" then
- direction = 3
- --Force
- elseif key == "f" and enabled and activating == false then
- if (attacking == false and blocking == false and stamina >= 170 and character.Torso:FindFirstChild("Left Shoulder"))
- and plr.Backpack:FindFirstChild("HasForce").Value == true then
- forceactive = true
- canblock = false
- canattack = false
- stamina = stamina - 170
- local pushtrack = Instance.new("Animation")
- pushtrack.AnimationId = "rbxassetid://365857748"
- local push = character.Humanoid:LoadAnimation(pushtrack)
- push:Play()
- local p = Instance.new("Part")
- p.Parent = game.Workspace
- p.CanCollide = false
- p.formFactor = "Symmetric"
- p.Shape = "Block"
- p.Size = Vector3.new(1,1,1)
- p.Transparency = 1
- p.Material = "Neon"
- game.Debris:AddItem(p,1)
- local handlepos = character["Left Arm"].CFrame
- local firingPoint = handlepos.p + handlepos:vectorToWorldSpace(Vector3.new(0, 0.4, -1.3))
- local shotCFrame = CFrame.new(firingPoint, character.Humanoid.TargetPoint)
- p.CFrame = shotCFrame + (shotCFrame.lookVector * (p.Size.Z / 2))
- local bodyVelocity = Instance.new('BodyVelocity')
- bodyVelocity.velocity = shotCFrame.lookVector * 300
- bodyVelocity.Parent = p
- local victim = nil
- p.Touched:connect(function(p)
- if p.Parent ~= character and p.Parent:FindFirstChild("Humanoid") then
- victim = p.Parent
- local hum = p.Parent:FindFirstChild("Humanoid")
- hum.Sit = true
- local PushBack = CFrame.new(p.Position, character.Torso.Position).lookVector * -80
- PushBack = Vector3.new(PushBack.X, -80, PushBack.Z)
- p.Velocity = PushBack
- local signal = Instance.new("ObjectValue")
- signal.Name = "ClashSignal"
- signal.Parent = hum
- end
- end)
- wait(0.4)
- forceactive = false
- if active then
- canblock = true
- canattack = true
- end
- coroutine.resume(coroutine.create(UpdateStamina))
- end
- end
- end)
- character.Humanoid.Running:connect(function(speed)
- if speed <= 0 then
- direction = 0
- end
- end)
- character.Humanoid.ChildAdded:connect(function(item)
- if item.Name == "Block" then
- local saber = character:FindFirstChild(ls)
- saber.Blade.CanClash.Value = true
- blocking = true
- canblock = true
- Blocking()
- elseif item.Name == "ClashSignal" then
- stamina = 0
- coroutine.resume(coroutine.create(UpdateStamina))
- Button2Up()
- item:Destroy()
- end
- end)
- function Blocking()
- while (blocking and canblock) and stamina > 0 do
- canattack = false
- candamage = false
- attacking = false
- stamina = stamina - 1
- coroutine.resume(coroutine.create(UpdateStamina))
- wait()
- end
- end
- tool.Equipped:connect(Selected)
- tool.Unequipped:connect(Deselected)
- end)
- end)
- ~~~~~~~~~~~~~~~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement