Code Monkey home page Code Monkey logo

Comments (1)

Emancyphur avatar Emancyphur commented on June 9, 2024

I'm sorry, but I am not familiar with that game. As a starting point, you can detect User Input with UserInputService.InputBegan, which returns an InputObject. You can then check the KeyCode property of the InputObject to see if it matches any of the keys that the player would need to press in order to activate that ability / power / etc.

Here's a quick example:

local UserInputService = game:GetService("UserInputService")

local abilityKeyCodes = {
    [1] = Enum.KeyCode.One,
    [2] = Enum.KeyCode.Two,
    [3] = Enum.KeyCode.Three
}

local function activateAbility(number)
-- There are other ways of implementing this, but this might be more intuitive to understand, to start
    if number == 1 then
        -- Run code related to the ability that should be activated with the "1" key
    elseif number == 2 then
        -- Run code related to the ability that should be activated with the "2" key
    elseif number == 3 then
        -- Run code related to the ability that should be activated with the "3" key
    end
end

UserInputService.InputBegan:Connect(function(inputObject, interactedWithUI)
    if interactedWithUI == true then return end

    local keyCode = inputObject.KeyCode
    local abilityCheck = table.find(abilityKeyCodes, keyCode)

    if abilityCheck then
        activateAbility(abilityCheck)
    end
end)

For future reference, this isn't the correct category for these kinds of questions. The "Issues" section of this repository is meant for highlighting issues with the code, models, etc. of my tutorials that have been posted here. If you have a suggestion for a future tutorial, you can post that in the Discussions category / section.

However, the question you asked here might be better suited for the Roblox Developer Forum. There are probably some existing threads on the Developer Forum where people have asked similar questions that were eventually solved, which might be able to help with answering your question(s) much faster than I'd be able to, especially since I don't know much about the game that you referenced.

from roblox-studio-tutorials.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.