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

How to make a clone of tool and then put it into player backpack?

I am trying to make a shop gui and one of the items is Grappling Hook. I have this script there are no errors but yet when I test it in studio it does not give me the grappling hook. I do have enough coins too when I test it. Here is the script.

local coins = script.Parent.Coins

for i, v in pairs(script.Parent.Frame:GetChildren()) do -- i got this idea from berezaa and yes it does work
	if v:IsA("TextButton" or "ImageButton") then
		v.MouseButton1Click:connect(function()
			if v.Name == "GrapplingHook" then -- these are the parts I'm concerned about
				if coins.Value > 349 then
					coins.Value = coins.Value - 350
					local clone = game.Lighting.GrapplingGun:Clone()
					clone.Parent = game.Players.LocalPlayer.Backpack
				end
			end
		end)
	end
end

3 comments

0

On line 6 you called in GraplingHook, but on line 9 GrapplingGun, this may be the problem

0

Is this in a LocalScript?

0

This is a local script

1 answer

✓ Accepted answer

I believe your problem is on the 4th line. Computers do exactly what you tell them, but sometimes can't understand some things that make sense to you and others as it.

In your example, you're trying to make the code continue if v is a TextButton or an ImageButton. The way you're writing it, the computer will not understand it and will only take the TextButton into account and will ignore the or bit altogether. The way you should write it is like this:

if v:IsA("TextButton") or v:IsA("ImageButton") then

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