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:
1 | clickdetector.MouseClick:Connect( function () |
2 |
3 | ChemicalXR = Instance.new ( "Tool" ) |
4 | ChemicalXR.Parent = game.StarterPack |
5 | ChemicalXR.Name = ( "ChemicalXR" ) |
6 |
7 | Handle = Instance.new ( "Part" ) |
8 | Handle.Parent = game.StarterPack.ChemicalXR |
9 | Handle.Name = ( "Handle" ) |
so it does create the tool and the handle in the starterpack but not ingame so you cant equip them.
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.
01 | local clickdetector = script.Parent.ClickDetector --(Wherever your clickdetector is) |
02 | local Tool = game.Lighting.Tool --Set tool to the name of the tool you made in lighting |
03 |
04 | function onClick(Clicker) |
05 |
06 | local c = game.Lighting.Tool:Clone() |
07 | c.Parent = Clicker.Backpack |
08 | end |
09 |
10 | clickdetector.MouseClick:Connect(onClick) |
Dont use StarterPack. Use Backpack from the local player. Heres the fixed version(not tested)
01 | clickdetector.MouseClick:Connect( function () |
02 |
03 | for i,v in pairs (game.Players:GetPlayers()) do |
04 | ChemicalXR = Instance.new ( "Tool" ) |
05 | ChemicalXR.Parent = v.Backpack |
06 | ChemicalXR.Name = ( "ChemicalXR" ) |
07 |
08 | Handle = Instance.new ( "Part" ) |
09 | Handle.Parent = ChemicalXR |
10 | Handle.Name = ( "Handle" ) |
11 | end |
I hope this worked and helped!