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

Is it possible to make something :Equip()?

Asked by 9 years ago

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

Log in to vote
1
Answered by 9 years ago

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)
0
thanks :D NinjoOnline 1146 — 9y
0
No problem. Spongocardo 1991 — 9y
0
They lose their equip when they die, can I just do a while true do loop? NinjoOnline 1146 — 9y
0
I have editted my question with the script fully NinjoOnline 1146 — 9y
0
Edited my answer Spongocardo 1991 — 9y
Ad

Answer this question