When a tool in workspace is touched, due to Roblox’s built-in tool behaviour, the tool moves into the character’s model, making it equipped.
My question is how can I choose which parent the tool should have when touched? For example, how can I make it parent to the backpack by default instead of parenting it to the character?
Here’s a simple server script that shows what’s happening:
local tool = workspace.Tool
print(tool.Parent) -- Output: Workspace
tool.Handle.Touched:Connect(function(Hit)
local plr = game.Players:GetPlayerFromCharacter(Hit.Parent)
if plr then
print(tool.Parent) -- Output: PlyDev (Character model name)
end
end)
Using my example question, “How can I make it parent to player’s backpack”, writing tool.Parent = game.Players.LocalPlayer.Backpack does work, however the tool still briefly parents to the character first. Is it possible to directly parent it to the backpack without that initial delay?
I understand that this is a fix to the topic name but for the question I ask in my description “How to choose which parent a tool should have when touched”, setting CanTouch to false stops anything from touching it at all.
oh sorry I didnt realise, this will work, but i didnt test it so it might allow the tool to enter the character for a split second before moving it. but maybe the script is fast enough so yea. you can add it into StarterPlayerScripts
local plr = game.Players.LocalPlayer
plr.CharacterAdded:Connect(function(character)
character.ChildAdded:Connect(function(tool)
if tool:IsA("Tool") then
tool.Parent = plr.Backpack
end
end)
end)
or if you want it even shorter. you can add this one in StarterCharacterScripts
script.Parent.ChildAdded:Connect(function(tool)
if tool:IsA("Tool") then
tool.Parent = plr.Backpack
end
end)
it seems more reliable too so js use this one. LOCAL SCRIPT BTW
I mean these scripts rely on a child being added so yes there is still a period where the tool is in the character.
Another scenario to better understand how I want it to work is let’s say I have a starter tool in starterpack and I try touch a tool in workspace while having the starter tool in my hand. With Roblox’s tool system, the two tools would swap places and I’d hold the new tool I touched. How can I make it so the tool I picked up goes in my backpack and the starter tool stays equipped?
if tool:IsA("Tool") then
-- he past equipped tool
local oldTool = character:FindFirstChildOfClass("Tool")
tool.Parent = plr.Backpack
if oldTool then
oldTool.Parent = character
end
end
ofcourse this would still cause the first tool to quickly unequip and equip. the only other fix is to make a custom tool pick up system.
Okay well I want to make it so the parent of the tool gets set directly to backpack, so I have made a custom tool pick up system. My only problem is how do I disable roblox’s default one since touching the tool in workspace still causes my character to equip it.
no dont remove the handle, every tool needs a handle. keep the handle for holding the tool, remove cantouch in it. then add another part called hitbox, allow cantouch. inside your custom script instead of detecting touches on the handle, detect it on the hitbox