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

Is it possible to make something :Equip()?

I have my own inventory and I was wondering is it possible so when the 1 button is pressed it equips their item in their backpack? I have done all the no. stuff, removed robloxs one and made it so when they click a button a sword is put in their backpack, but I don't know how to make it so its equipped. Is there something like :Equip() or something?

script.Parent.StartGui.ClassFrame.Buttons.PlayKnightButton.MouseButton1Down:connect(function(onClick)
	script.Parent.Inventory.MainFrame.InvSpace.Inv1.Image = "rbxasset://Textures/Sword128.png"
    local Item = game:GetService("ReplicatedStorage").Weapons.Sword
    Item:Clone().Parent = game.Players.LocalPlayer.Backpack
    Item:Clone().Parent = game.Players.LocalPlayer.StarterGear
    char:WaitForChild("Humanoid"):EquipTool(player.Backpack:GetChildren())
end)

1 answer

✓ Accepted answer

Yes, there is a method in Humanoid called EquipTool(). It's basically the same as parenting a tool to the player's character. For hopperbins, I'm not too sure but this definitely works for tools. Below is an example of how to equip a tool after 5 seconds of when you spawn:

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		wait(5)
		char:WaitForChild("Humanoid"):EquipTool(player.Backpack.Tool) --Change Tool to the name of the Tool.
	end)
end)

Method page: http://wiki.roblox.com/index.php?title=EquipTool_(Method)

EDIT:

script.Parent.StartGui.ClassFrame.Buttons.PlayKnightButton.MouseButton1Down:connect(function()
	script.Parent.Inventory.MainFrame.InvSpace.Inv1.Image = "rbxasset://Textures/Sword128.png"
	local Item = game:GetService("ReplicatedStorage").Weapons.Sword:Clone()
	item.Parent = game.Players.LocalPlayer.Backpack
	local item2 = game:GetService("ReplicatedStorage").Weapons.Sword:Clone()
	item2.Parent = game.Players.LocalPlayer.StarterGear
	game.Players.LocalPlayer.Character:WaitForChild("Humanoid"):EquipTool(item)
end)

5 comments

0

thanks :D

0

No problem.

0

They lose their equip when they die, can I just do a while true do loop?

0

I have editted my question with the script fully

0

Edited my answer

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