Why won't these functions give me tools?

These functions are not correct and I don’t know how to change it, can anybody help?

You don’t appear to be calling the GiveGadget and GiveWeapon functions.
Another thing, you are trying to pass an instance into WaitForChild, not a string. Try v.Name instead.

Also are there any errors in the output?


Here is some of my code that call the functions.


Here is the error that displays.

It appears you’re trying to call WaitForChild() on the strings, not the Gadgets and Weapons objects. Add an “s” to those like this.

Gadgets:WaitForChild(v):Clone().Parent = PlayerBackpack
Weapons:WaitForChild(v):Clone().Parent = PlayerBackpack

Also you should be fine with just ‘v’, my apologies.

image
We’re getting there

Could you show me the following stack and the line of code it mentions?

1 Like

You don’t do v.Name, just v.

This is a bit off-topic, but please use code blocks for better readability

1 Like

	for i, v in ipairs(Weapon) do
	Gadgets:WaitForChild(v):Clone().Parent = PlayerBackpack
	end
end

Read the error, please. It is clearly stating that you are passing in a string in ipairs rather than a table. I see that in some parts of your code, this is true.

Try this:

if typeof(Weapon) == "string" then Weapon = {Weapon} end

for _, weapon in ipairs(Weapon) do
    Gadgets:WaitForChild(v):Clone().Parent = PlayerBackpack
end
1 Like

image

Here you can see, you are passing strings to the function and then running a for loop looping through a string instead of a table, and thats the reason why it gives that error

2 Likes