Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I fix this onTouch? [ SOLVED ]

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

✓ Accepted answer
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

2 comments

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?

1

i figured it out, thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.