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

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

Asked by 6 years ago
Edited 6 years ago

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);
0
I've pulled handfuls of hair, it's a fairly steep learning curve. matbelle 15 — 6y

1 answer

Log in to vote
0
Answered by
ax_gold 360 Moderation Voter
6 years ago

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.

0
many thanks, I was able to get it working matbelle 15 — 6y
Ad

Answer this question