Goal Allow a player to hold a "Gun" without using a tool object, as i have toolbar disabled for my fps game.
ProblemThe code gives me this error: 11:24:49.896 - Players.Player.PlayerScripts.Loadout:10: attempt to call method 'clone' (a nil value)
Code
"Cloner"
plr = game.Players.LocalPlayer char = plr.Character lo = game.ReplicatedStorage.Loadout pmr = lo.Rifle char:WaitForChild("Humanoid") if char.Humanoid then gc = pmr:GetChildren() gc:Clone() gc.Parent = char else wait() end
Welding
selected = false RSH, LSH = nil, nil GRP = nil RW, LW = Instance.new("Weld"), Instance.new("Weld") anim = "none" function WaitForChild(obj, ch_n) local t = time() while not obj:FindFirstChild(ch_n) and time() - t < 10 do wait(0.1) end return obj:FindFirstChild(ch_n) end script.Parent.Equipped:connect(function() if selected then return end selected = true player = game.Players:playerFromCharacter(script.Parent.Parent) local ch = script.Parent.Parent WaitForChild(ch, "Torso") RSH = WaitForChild(ch.Torso, "Right Shoulder") LSH = WaitForChild(ch.Torso, "Left Shoulder") GRP = WaitForChild(ch["Right Arm"], "RightGrip") _G.Grip = GRP -- RSH.Part1 = nil LSH.Part1 = nil -- RW.Part0 = ch.Torso RW.C0 = CFrame.new(1.5, 0.5, 0) --* CFrame.fromEulerAnglesXYZ(1.3, 0, -0.5) RW.C1 = CFrame.new(0, 0.5, 0) RW.Part1 = ch["Right Arm"] RW.Parent = ch.Torso _G.R = RW -- LW.Part0 = ch.Torso LW.C0 = CFrame.new(-1.5, 0.5, 0) --* CFrame.fromEulerAnglesXYZ(1.7, 0, 0.8) LW.C1 = CFrame.new(0, 0.5, 0) LW.Part1 = ch["Left Arm"] LW.Parent = ch.Torso _G.L = LW -- GRP.C0 = CFrame.new(0, -1, -0.5) * CFrame.fromEulerAnglesXYZ(-1.22, -0.45, 0.22) for i = 0, 1, 0.05 do wait() RW.C0 = CFrame.new(1.5, 0.5, 0.25) * CFrame.fromEulerAnglesXYZ(1.3*i, 0, -0.5*i) LW.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(1.7*i, 0, 0.8*i) LW.C1 = CFrame.new(0.3*i, 1+1*i, 0) end wait() local rg = (ch["Right Arm"]:FindFirstChild("RightGrip") or GRP) if rg ~= GRP then GRP.Parent = ch["Right Arm"] rg:remove() end end) script.Parent.Unequipped:connect(function() selected = false local pl = player RW.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0) LW.C0 = CFrame.new(0,0,0) * CFrame.fromEulerAnglesXYZ(0,0,0) LW.C1 = CFrame.new(0,0,0) RW.Parent = nil LW.Parent = nil RSH.Part1 = pl.Character["Right Arm"] LSH.Part1 = pl.Character["Left Arm"] end) function armReload() for i = 0, 1, 0.1 do wait() LW.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(1.3*i, 0, 0.9*i) LW.C1 = CFrame.new(0.3*i, 1+1*i, 0) end end function gunOut() for i = 0, 0.3, 0.06 do wait() GRP.C0 = CFrame.new(0+i, -1-i, 0+(2*i)) * CFrame.fromEulerAnglesXYZ(-2.22, -0.45, 0.42) LW.C0 = CFrame.new(-1, 0.5, 0) * CFrame.fromEulerAnglesXYZ(4.2, 0, 2.9) LW.C1 = CFrame.new(0.8*i, 1.1+i, -0.3) end end function gunReturn() RW.C0 = CFrame.new(1.5, 0.5, 0.25) * CFrame.fromEulerAnglesXYZ(1.3, 0, -0.5) LW.C0 = CFrame.new(-1.5, 0.5, 0) * CFrame.fromEulerAnglesXYZ(1.7, 0, 0.8) LW.C1 = CFrame.new(0.3, 1+1, 0) GRP.C0 = CFrame.new(0, -1, -0.5) * CFrame.fromEulerAnglesXYZ(-1.22, -0.45, 0.22) end