Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Wait(.1)
- Player = game.Players.LocalPlayer
- Character = Player.Character
- LArm = Character:FindFirstChild("Left Arm")
- Torso = Character:FindFirstChild("Torso")
- Shoulder = Torso:FindFirstChild("Left Shoulder")
- ShieldTemplate = script:WaitForChild("ShieldTemplate")
- VariantShield = script:WaitForChild("VariantShield")
- RemoveFunction = script:WaitForChild("RemoveShield")
- Use = false
- DataY = 0
- Up = false
- Down = false
- Busy = false
- AnimationSpeed = 5 -- Slower, smoother with more integers
- ShieldLink = nil
- Weld = nil
- LeftShoulderMotor = nil
- local function WeldDecoration(Variant, WeldTo)
- local g = Variant:Clone()
- g.Parent = WeldTo.Parent
- local C = g:GetChildren()
- for i = 1, #C do
- if C[i]:IsA("BasePart") then
- C[i].CanCollide = true
- local W = Instance.new("Weld")
- W.Part0 = g.Middle
- W.Part1 = C[i]
- local CJ = CFrame.new(g.Middle.Position)
- local C0 = g.Middle.CFrame:inverse()*CJ
- local C1 = C[i].CFrame:inverse()*CJ
- W.C0 = C0
- W.C1 = C1
- W.Parent = g.Middle
- end
- local Y = Instance.new("Weld")
- Y.Part0 = WeldTo
- Y.Part1 = g.Middle
- Y.C0 = CFrame.new(0, 0, 0)
- Y.Parent = Y.Part0
- end
- local h = g:GetChildren()
- for i = 1, # h do
- h[i].Anchored = false
- h[i].CanCollide = false
- end
- end
- local function CreateShield()
- Shield = ShieldTemplate:Clone()
- Shield.Name = "Shield"
- Shield.Parent = Character
- WeldDecoration(VariantShield, Shield.Handle)
- Shield:MoveTo(Character.Torso.Position)
- ShieldWeld = Instance.new("Weld", Shield)
- ShieldWeld.Part0 = LArm
- ShieldWeld.Part1 = Shield.Handle
- ShieldTag = Instance.new("StringValue", Shield.Handle)
- ShieldTag.Name = "IsShield"
- ShieldTag.Value = "Wood"
- ShieldWeld.C0 = CFrame.new(-0.175, -0.1, 0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(90), 0)
- ShieldLink = Shield
- end
- function CommandIssued(Type, Data)
- if Type == "KeyPress" and Data ~= nil then
- Key = Data:lower()
- if Key == "q" then
- if not Use and not Busy then
- Busy = true
- if not Character:FindFirstChild("Shield") then
- CreateShield()
- end
- LeftShoulderMotor = Torso["Left Shoulder"].C1 -- Save data
- Shoulder.Part1 = nil -- Disconnect arm from shoulder
- Weld = Instance.new("Weld") -- New Weld LeftArm to Torso
- Weld.Name = "LeftArm Weld"
- Weld.Part0 = Torso
- Weld.Part1 = LArm
- Weld.Parent = Torso
- Weld.C0 = CFrame.new(-1.5,0,0) -- Reposition arm
- for i = 1,AnimationSpeed do
- Weld.C0 = Weld.C0 * CFrame.new(0.5/AnimationSpeed,-0.25/AnimationSpeed,-1/AnimationSpeed)*CFrame.fromEulerAnglesXYZ(math.rad(70/AnimationSpeed),math.rad(-40/AnimationSpeed),math.rad(40/AnimationSpeed)) -- if you tweak the numbers long enough you manage to get a smooth animation, sometimes it takes really long until you finally get all the positions right but when it comes to cframe/Weld manipulation the best way to achieve the wanted formula is trough trial and error
- Wait()
- end
- Busy = false
- Use = true
- else
- if not Busy then
- Busy = true
- if DataY > 0 then
- for i = 1, DataY do
- DataY = DataY - 1
- Weld.C0 = Weld.C0 * CFrame.new(0,0,0.04)*CFrame.fromEulerAnglesXYZ(math.rad(-3),math.rad(1),math.rad(0))
- if ShieldWeld ~= nil then
- ShieldWeld.C0 = ShieldWeld.C0 * CFrame.new(.02, 0, .015) * CFrame.fromEulerAnglesXYZ(math.rad(.9), math.rad(-2), math.rad(.75)) -- SHIELD WELD HERE
- end
- Wait()
- end
- end
- for i = 1, AnimationSpeed do
- Weld.C0 = Weld.C0*CFrame.new(-0.5/AnimationSpeed,0.25/AnimationSpeed,1/AnimationSpeed)*CFrame.fromEulerAnglesXYZ(math.rad(-70/AnimationSpeed),math.rad(40/AnimationSpeed),math.rad(-40/AnimationSpeed)) -- the equiping animation reversed
- Wait()
- end
- ShieldWeld.C0 = CFrame.new(-0.175, -0.1, 0) * CFrame.fromEulerAnglesXYZ(math.rad(90),math.rad(90), 0)
- Weld:Destroy()
- Shoulder.Part1 = LArm
- Shoulder.C1 = LeftShoulderMotor
- DataY = 0
- Use = false
- Busy = false
- end
- end
- elseif Key == "r" then
- if Up == false and Down == false and Use == true and Busy == false then
- Up = true
- while Up == true and DataY < 30 do
- DataY = DataY + 1
- Weld.C0 = Weld.C0 * CFrame.new(0, 0, -0.04) * CFrame.fromEulerAnglesXYZ(math.rad(3),math.rad(-1),math.rad(0))
- if ShieldWeld ~= nil then
- ShieldWeld.C0 = ShieldWeld.C0 * CFrame.new(-.02, 0, -.015) * CFrame.fromEulerAnglesXYZ(math.rad(-.9), math.rad(2), math.rad(-.75)) -- SHIELD WELD HERE
- end
- Wait()
- end
- end
- elseif Key == "f" then
- if Down == false and Up == false and Use == true and Busy == false then
- Down = true
- while Down == true and DataY > 0 do
- DataY = DataY-1
- Weld.C0 = Weld.C0 * CFrame.new(0, 0, 0.04) * CFrame.fromEulerAnglesXYZ(math.rad(-3),math.rad(1),math.rad(0))
- if ShieldWeld ~= nil then
- ShieldWeld.C0 = ShieldWeld.C0 * CFrame.new(.02, 0, .015) * CFrame.fromEulerAnglesXYZ(math.rad(.9), math.rad(-2), math.rad(.75)) -- SHIELD WELD HERE
- end
- Wait()
- end
- end
- end
- elseif Type == "Remove" then
- if Weld then
- Weld:Destroy()
- end
- Shoulder.Part1 = LArm
- if ShieldLink then
- ShieldLink:Destroy()
- end
- end
- end
- function CommandStopped(Key)
- Key = Key:lower()
- if Key == "r" then
- Up = false
- elseif Key == "f" then
- Down = false
- end
- end
- function RemoveFunction.OnClientInvoke()
- CommandIssued("Remove")
- end
- CreateShield()
- Player:GetMouse().KeyDown:connect(function(Key)
- CommandIssued("KeyPress", Key)
- end)
- Player:GetMouse().KeyUp:connect(CommandStopped)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement