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

I am trying to make it so that if you click a part you get a tool. Why do you need a "?"

Asked by 6 years ago

So basically the title says it all i dont know what more to say sorry. well i have a piece of code but it isnt working so im asking for advice on why its not working here

I have a part with a clickdetector and a script with following content:

clickdetector.MouseClick:Connect(function()

    ChemicalXR = Instance.new ("Tool")
    ChemicalXR.Parent = game.StarterPack
    ChemicalXR.Name = ("ChemicalXR")

    Handle = Instance.new ("Part")
    Handle.Parent = game.StarterPack.ChemicalXR
    Handle.Name = ("Handle")


so it does create the tool and the handle in the starterpack but not ingame so you cant equip them.

0
I'd advise you to create the tool in studio but Clone it into the StarterPack noobest_khun -10 — 6y

2 answers

Log in to vote
0
Answered by
Voy1980 111
6 years ago

What you need to do is to get a tool like what noobest_khun said and put it somewhere not "physical", such as lighting or replicated storage. Afterwards, you would make a clone in your script and set the clones parent to the players backpack because making one from a script like that would be a LOT of work.

local clickdetector = script.Parent.ClickDetector --(Wherever your clickdetector is)
local Tool = game.Lighting.Tool --Set tool to the name of the tool you made in lighting

function onClick(Clicker)

local c = game.Lighting.Tool:Clone()
c.Parent = Clicker.Backpack
end

clickdetector.MouseClick:Connect(onClick)
0
ew don't put it in Lighting! This is not for storage! User#19524 175 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Dont use StarterPack. Use Backpack from the local player. Heres the fixed version(not tested)

    clickdetector.MouseClick:Connect(function()

for i,v in pairs(game.Players:GetPlayers()) do
        ChemicalXR = Instance.new ("Tool")
        ChemicalXR.Parent = v.Backpack
        ChemicalXR.Name = ("ChemicalXR")

        Handle = Instance.new ("Part")
        Handle.Parent = ChemicalXR
        Handle.Name = ("Handle")
end


I hope this worked and helped!

Answer this question