Press Keybind to toggle aura

I am trying to make a keybind toggle for an aura, it’s showing no script error but nothing happens when I try to execute it while testing.

I am pretty new to scripting, planning on learning soon but I got this script “done” with reference of another script which has aura toggle by button.

I haven’t tried any solutions because well, clarified above; new to scripting. So if anyone could give me an advice or see what’s wrong with the script, greatly would help!

I do not ask for anyone to remake the script ENTIRELY, I just need a bit of help to see what to add to make the script work properly.

local auraEvent = game.ReplicatedStorage.AuraEvent
local toggle = false
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()

if input.KeyCode == Enum.KeyCode.K then
	toggle = true
	auraEvent:FireServer(char)
else
	toggle = false
	char.HumanoidRootPart.Effect:Destroy()
end

You did not use UserInputService so there is no way to detect when the player presses the keybind.

local auraEvent = game.ReplicatedStorage.AuraEvent
local toggle = false
local player = game.Players.LocalPlayer or game.Players.PlayerAdded:Wait()
local char = player.Character or player.CharacterAdded:Wait()
local uis = game:GetService("UserInputService")

uis.InputBegan:Connect(function(input, isTyping)
   if isTyping then return end
  if input.KeyCode == Enum.KeyCode.K then
	toggle = true
	auraEvent:FireServer(char)
else
	toggle = false
	char.HumanoidRootPart.Effect:Destroy() -- Here you only destroy the aura on the client side, so the other players will still see it (That is if you added the effect on a server script)
end 
end)

2 Likes

Ah. I see. Thank you! It works now, after just a few tweaks.

1 Like