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

how do i equip a tool from a menu?

Asked by 6 years ago
Edited 6 years ago

so i'm experimenting right now to make a game and i have an inventory gui. i have a button that is supposed to move the tool into starter pack but i have a custom backpack, here is the script for it :

 game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.PlayerList,false)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)

local plr = game.Players.LocalPlayer
local char = plr.Character
local UIS = game:GetService('UserInputService')
local equipped = false 

UIS.InputBegan:connect(function(input)
    if input.KeyCode == Enum.KeyCode.R then
        if equipped == false then 
            char.Humanoid:EquipTool(plr.Backpack:WaitForChild('ClassicSword'))
            equipped = true
        else
            equipped = false
            char.Humanoid:UnequipTools()
        end
    end
end)

I have the tool as a child in the inventory gui and i made a script so when you click it it moves the tool to starter pack, here is the script :

local slot1 = script.Parent.slot1
local sword = script.Parent.ClassicSword

slot1.MouseButton1Click:connect(function()
    sword.Parent = game.StarterPack
end)

It moves the tool to the starterpack, but when i press R it doesn't equip. any help?

0
You would want to fire a remote event Earthkingiv 51 — 6y
0
And fire server to move the sword to starterpack. Earthkingiv 51 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

StarterPack only clones items in it into the player’s backpack when the player joins/respawns. Also note that StarterPack affects ALL players.

For players that didn’t respawn/join when the item is added to StarterPack, they can’t equip it because the item isn’t in their Backpack yet, so that :WaitForChild() you added there is going to stall forever until the player resets.

The way I would fix and do this is to make a folder in the player and name it “CustomBackpack” or whatever. I would then clone the sword to that folder instead of putting it in StarterPack where everyone can get it. You can then make your script find the sword in the folder and use :EquipTool() on it.

Hoped this helped!

Ad

Answer this question