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

How do I use number input keys in scripts to trigger them (EX. Weapon swap)?

Asked by 10 years ago

What I want to do is use the # keys on the keyboard to trigger certain scripts. (Preferably 2 in this case)

local mouse = game.Players.LocalPlayer:GetMouse()
local emp = false

function getTool()  
    for _, kid in ipairs(script.Parent:GetChildren()) do
        if kid.className == "Tool" then return kid end
    end
    return nil
end


mouse.KeyDown:connect(function (key) -- Run function
    if key == "2" then   <---[[PROBLEM RIGHT HERE. I want this to be 2, it works with "q", but I need numbers, not letters]]
        emp = true
        print("EMPon")
        local character = script.Parent
        local player = game.Players:GetPlayerFromCharacter(character)
        player.EMPon = true
        if player.EMPon == true then
            EMPvictim = player.EMPvictim
            repeat wait()
            until EMPvictim.Value ~= nil
            victim = game.Players:FindFirstChild(""..EMPvictim.Value)
            player.PlayerGui.EMP.Adornee = victim
        end
        end
end)

1 answer

Log in to vote
0
Answered by
Bebee2 195
10 years ago

I believe SetCoreGuiEnabled will allow you to use the number keys if you disable backpack.

Otherwise, try InputBegan

-- Example:
game:service'UserInputService'.InputBegan:connect(function(obj)
if obj.KeyCode == 'One' and obj.UserInputState == 'Begin' then -- I believe this would work.
print'1 was pressed that day.'
end
end)
0
How would I script that using the script I wrote? InputBegan look's simpler. Orlando777 315 — 10y
0
HOLD IT I forgot something. Bebee2 195 — 10y
0
Not sure if it would work 100% tho. Give it a shot. Bebee2 195 — 10y
0
Nope. Doesn't work at all :/ Orlando777 315 — 10y
Ad

Answer this question