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

[Solved] onKeyPress equip tools, not working ingame but in studio?

Thanks to ax_gold, got this working script now:

local player = game.Players.LocalPlayer
local backpack = player.Backpack
local character = player.Character
local primary = backpack.Primary
local secondary = backpack.Secondary

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.One then
        primary.Parent = character
secondary.Parent = backpack
            elseif inputObject.KeyCode == Enum.KeyCode.Two then
        secondary.Parent = character
primary.Parent = backpack
    end
end

 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Health, false);

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

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

1 comment

0

I've pulled handfuls of hair, it's a fairly steep learning curve.

1 answer

EquipTool() Likes to be especially stupid when it comes to roblox scripting. Instead, I usually just change the parent of the tool to the character in workspace, and it will automatically make them equip the tool. Here's an example with part of your script.

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.One then
        backpack.Primary.Parent = character
            elseif inputObject.KeyCode == Enum.KeyCode.Two then
        backpack.Secondary.Parent = character
    end
end

also, just a side note, but you might want to make a way to unequip the tool. If you need help with that too, let me know.

1 comment

0

many thanks, I was able to get it working

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