Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Indirect tool holding? *Edited*

Asked by
adatax 5
8 years ago

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
0
We don't either. This isn't a request site. User#6546 35 — 8y
0
It was not a request i was asking what was wrong with it,. adatax 5 — 8y
0
How are we supposed to know what's wrong with it? It's your code. Tell us what's wrong with it, then perhaps we can help. Perci1 4988 — 8y
0
updated it with the issue and error i was given adatax 5 — 8y

Answer this question