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

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

Asked by 9 years ago

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
0
On line 6 you called in GraplingHook, but on line 9 GrapplingGun, this may be the problem Mystdar 352 — 9y
0
Is this in a LocalScript? Discern 1007 — 9y
0
This is a local script raystriker6707 30 — 9y

1 answer

Log in to vote
0
Answered by 9 years ago

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
Ad

Answer this question