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

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

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

✓ Accepted answer

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)

8 comments

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?

0

Yes, you should put it into replicatedstorage/lighting/serverstorage or something :)

0

I put it in ReplicatedStorage but it still goes to the tool's position.

0

That's strange. Did you make the tool or is it a model?

0

I set it as a tool and put a part named "Handle"

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

0

I'll try that.

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

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