Attempt to index string with `Parent` (line 48)

Hi.
Im currently working on a Weapon Dealer and in the code snippet I will share here, I have a table “result” where all weapon names (Strings) are in the player owns. In rep.Weapons are all existing Weapons. I want to achieve, that all weapons in “result” should copy into the players backpack. But when I try to clone the weapon out of rep.Weapons and set the parent, I become the error which is in the title.

Its a script inside ServerScriptService. Heres the code:

for i, v in pairs(result) do
			for s, w in pairs(rep.Weapons:GetChildren()) do
				if v == w.Name then
					local tool = w:Clone()
					print(tool.ClassName, w ,v)
					tool = w.Name
					tool.Parent = plr.Backpack
				end
			end
		end

w.Name is a string value, not a roblox object. You can’t use Parent on it

1 Like

Did you mean tool.Name = w.Name?

If so, you don’t have to include that line because cloning the tool also copies the name.

1 Like

I printed the w.ClassName and it gave me “Tool”

Lmao I COMPLETELY oversaw this xD. That makes now also sense because this line made it to a string. Thank you!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.