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

Why can't I put a tool in my toolbar?

Asked by 4 years ago

I'm trying to make it so that when a player presses E, a tool goes into their toolbar, but when I run this code and press E, in the explorer the tool is in the starter pack but not in the toolbar. (This is in a local script inside StarterPlayerScripts)

local Demo = game.Workspace.Demo
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        Demo.Parent = game.StarterPack
    end
end)

1 answer

Log in to vote
1
Answered by
skyaz1 72
4 years ago

In order to put a tool into someone's toolbar, you need to put it into their Backpack, which can be accessed through player.Backpack. So,we make a clone of the Demo tool and put that clone into the player's backpack

local Demo = game.Workspace.Demo
    local UIS = game:GetService("UserInputService")
    UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        local DemoClone = Demo:Clone() -- the reason we want to clone it is so we can use the tool again, if we didn't clone the tool would be put into the player and would not be inside Workspace anymore to use later
    DemoClone.Parent = game.Players.LocalPlayer.Backpack--this is where to put then tool, not the starterpack.  It will put the tool inside the local player's backpack
        end
    end)

Code without comments:

local Demo = game.Workspace.Demo
    local UIS = game:GetService("UserInputService")
    UIS.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.E then
        local DemoClone = Demo:Clone() 
    DemoClone.Parent = game.Players.LocalPlayer.Backpack
        end
    end)
0
Thanks, this put it in the backpack, but when i equip it my player goes to the position where i put the tool in the workspace. Do I fix this by putting it in ReplicatedStorage or doing something else? ack_superbear 35 — 4y
0
Yes, you should put it into replicatedstorage/lighting/serverstorage or something :) skyaz1 72 — 4y
0
I put it in ReplicatedStorage but it still goes to the tool's position. ack_superbear 35 — 4y
0
That's strange. Did you make the tool or is it a model? skyaz1 72 — 4y
View all comments (4 more)
0
I set it as a tool and put a part named "Handle" ack_superbear 35 — 4y
0
Also, I recommend changing the grip position and position of the tool, that may also help. If it's a model, the script may be outdated skyaz1 72 — 4y
0
I'll try that. ack_superbear 35 — 4y
0
Also, I did the same thing myself, I made a part in workspace, named it handle, put it into a tool named demo and everything worked fine skyaz1 72 — 4y
Ad

Answer this question