How do I create an aura Keybind script?

Hi, so I am a beginner scripter and I want to make an aura that can be turned on and off by pressing a key on the player’s keyboard. I don’t know how to start off but I wanted to try putting something together to see where that would take me but I got stuck.

The problem I have now is that I don’t know how to continue the code and not sure where I would need to put my codes in so that it would work. I think the aura itself is supposed to be put in Replicated Storage but as for the scripts i’m not sure.

This is what I have done so far:
aura%20script

2 Likes

You will want to do this using UserInputService events such as InputBegan. Here is a developerhub article to get you headed in the right direction. UserInputService | Documentation - Roblox Creator Hub

2 Likes

Have you created a server-side script that actually makes the aura function when the event is fired?

The most common way to detect input is using UserInputService or ContextActionService:

You would have your central activation function, which is just your code:

local toggle = false
local function AuraTrigger()
    toggle = not toggle
    if toggle then
        AuraEvent:FireServer()

    else -- this is pseudocode!
        local Effect = -- find effect
        Effect:Destroy()
    end
end

We can then just call this function when we want the aura to be toggled.

UserInputService has 3 events (InputBegan, InputEnded, and InputChanged) you can listen to to figure out what action to take.

In this example, I look at the returned input object’s KeyCode to find out whether I should call AuraTrigger or not:

local UserInputService = game:GetService("UserInputService")

local function onInputBegan(input, gameProcessed)
    if not gameProcessed then -- if Gui's are not overriding the input,
        if input.KeyCode == Enum.KeyCode.F then -- if the key pressed is F,
            AuraTrigger()
        end
    end
end

UserInputService.InputBegan:Connect(onInputBegan)

ContextActionService uses the concepts of “actions” to run functions based on a specific key you pressed. You can bind these actions with ContextActionService:BindAction and unbind them using ContextActionService:UnbindAction.

In this example, I just binded an action named AuraToggle to the F keycode enum, and I read the returned state enum to see if the player is pressing the key down:

local ContextActionService = game:GetService("ContextActionService")

local function onFPress(name, state, input)
    if state == Enum.UserInputState.Begin then -- if the key is pressed
        AuraTrigger()
    end
end

ContextActionService:BindAction(
    "AuraToggle",
    onFPress,
    false,
    Enum.KeyCode.F -- you can fit more in here if you want
)
1 Like

That was one of the things that got me stuck, I wasn’t sure how to go about it

Thank you for the help, it didn’t work I think mainly because of the script I put in the sever script service area, it didn’t show anything wrong in the output but when I press the key " f " nothing happens. Either way your post helped me learn a lot and ill have to look more in to “UserInputService” and “ContextActionService”.

heres what I did for the ServerScriptServices code.
I looked at a fireball script to see if I can alter it and make it work for this one

2 Likes