#need help with keybinds conditions

1 messages · Page 1 of 1 (latest)

indigo ravine
#

i want to make it so the the function that involves clicking E is only available when the tool is equipped. however idk how to do it can someone help ?
this is what i have

local Plr = game.Players.LocalPlayer
local Char = Plr.Character
local Humanoid = Plr.Character.Humanoid
local Mouse = Plr:GetMouse()

local r = game:GetService("ReplicatedStorage")

local Uis = game:GetService("UserInputService")

local Tool = script.Parent
local CastAnimation = Humanoid.Animator:LoadAnimation(script.Anim)
local AbilityRemote = r.AbRemote.AbilityRemote

local CanUse = false

Tool.Equipped:Connect(function()
CanUse = true
end)

Tool.Unequipped:Connect(function()
CanUse = false
end)

Uis.InputBegan:Connect(function(input, gameProcessedEvent)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.E then
local MousePos = Mouse.Hit.Position
CastAnimation:Play()
AbilityRemote:FireServer("ThrowBall", MousePos)

    end
end

end)

lost cloak
#

Usually key on keyboard have specific code numbers

#

Past it into ChatGPT

shy willow
#

there doesnt seem to be any code checking if CanUse is true when E is pressed

indigo ravine