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

How do I fix this onTouch? [ SOLVED ]

Asked by 10 years ago

What this does, is if I touch the brick, it will clone my StarterGear and paste it into my backpack. The error I am getting is: Workspace.Weapon Taker.Script.Remove:5:Attempt to call method ('Clone' a nil value)

Here is my code:

function onTouch(obj)
    if obj.Parent:findFirstChild("Humanoid")~=nil then
        p=game.Players:findFirstChild(obj.Parent.Name)
        if p~=nil and p.Chakra.Value == "none" then
            ch=p.Backpack:getChildren():Clone()
            ch.Parent = p.Backpack
            p.Chakra.Value = good

        elseif p.Chakra.Value == "good" then
            print("good")

        end
    end
end
script.Parent.Touched:connect(onTouch)

1 answer

Log in to vote
1
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago
ch=p.Backpack:getChildren():Clone()

GetChildren returns a table of all the children of Backpack, and you can't call Clone() on a table. You can call it on each item in a table though.

ch=p.Backpack:getChildren()
for _,child in pairs(ch) do
    local clone = child:Clone()
    clone.Parent = p.Backpack
    clone.Chakra.Value = good
end
0
Here is the problem, I have a brick in the lobby remove the swords from players, is there a way in my brick that clears their backpack to save that data and send it to this script to paste a clone into the players backpack? ggggyourface23 63 — 10y
1
i figured it out, thanks! ggggyourface23 63 — 10y
Ad

Answer this question