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

I have this script in my tool, but I want it to automatically hold the Tool. How?

script.Parent.Handle.Touched:connect(function(hit) 
pcall(function() 
player = game.Players:getPlayerFromCharacter(hit.Parent) 
script.Parent:Clone().Parent = player.Backpack 
script.Parent:Remove() 
end) 
end)

How do I make it automatically hold the item when grabbed or taken off the ground?

1 answer

✓ Accepted answer

Hi ken,

You make the Player equip the tool by parenting the tool to the Character. What you're trying to do is quite simple and I just made a short script that accomplishes it. I would hope that you examine this script and learn from it, it's the best way to learn how to do what you're asking.

local part = script.Parent; -- The part that has the tool.

part.Touched:Connect(function(obj)
	local hum = obj.Parent:FindFirstChildOfClass("Humanoid"); -- To check if a player touched the part.
	
	if hum then -- Checks if it's a player that touched the part.
		local tool = script.Parent:WaitForChild("ToolToGive"):Clone(); -- Clones the tool.
		
		tool.Parent = obj.Parent; -- Parents it to the Character
		
		part:Destroy(); -- Destroys the part so nobody else can get the tool.
	end
end)

##Well, hope I helped and have a fabulous day/night.

Thanks,

Best regards,

~~ KingLoneCat

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