Hello there,
I am having trouble getting my animated shield to work. Basically I changed it from having c-frames to animations so it would be easier to update but I seem to be having trouble. Does anyone know how to fix this? Any help is appreciated.
Error
Code
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:wait()
local equipped = false
local up = false
local baseShield = script.Parent.Parent
local shield
local UserInputService = game:GetService('UserInputService')
local animation = Instance.new("Animation")
animation.AnimationId = "http://www.roblox.com/Asset?ID=1956514250"
---------------------|CODE BELOW|------------------------
print("Step0")
player:GetMouse().KeyDown:connect(function(k)
if not character:findFirstChild("Left Arm") then return end
if not character:findFirstChild("Torso") then return end
if not character.Torso:findFirstChild("Left Shoulder") then return end
local lsh = character.Torso:findFirstChild("Left Shoulder")
if k == "v" then --Spawns the Shield to the Left Arm
equipped = not equipped
lsh.Part1 = character["Left Arm"]
print("Step1")
if equipped then
shield = baseShield:clone()
local handle = shield:findFirstChild("Handle")
for n,i in pairs(shield:GetChildren()) do
if i.Name ~= "Handle" and i:IsA("BasePart") then
local nw = Instance.new("Weld",i)
nw.Part0 = handle
nw.Part1 = handle
nw.C0 = handle.CFrame:inverse()
nw.C1 = i.CFrame:inverse()
elseif (i:IsA("Script") or i:IsA("LocalScript")) then
i:remove()
end
end
handle.Anchored = false
print("Step2")
shield.Parent = character
shield:MakeJoints()
local nw = Instance.new("Weld",character["Left Arm"])
nw.Part0 = character["Left Arm"]
nw.Part1 = handle
nw.C1 = CFrame.new()
nw.Name = "LeftGrip"
else
if character["Left Arm"]:FindFirstChild("LeftGrip") then
character["Left Arm"].LeftGrip:remove()
end
if shield then
shield:remove()
end
print("Step3")
end
elseif k == "x" and equipped then --Raise Shield
up = not up
if up then
lsh.Part1 = nil
local w = Instance.new("Weld",shield)
w.Part0 = character.Torso
w.Part1 = character["Left Arm"]
animation:play()
else
animation:stop()
end
end
end)