Hello. I need help detecting a keypress from inside a tool.
I have a tool with a localscript in it, and inside the localscript there is a remoteevent.
This is the localscript code:
local tool = script.Parent
local equipped = false
local UID = game:GetService("UserInputService")
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
UID.InputBegan:Connect(function(key,isTyping)
if isTyping == false then
if equipped == true then
print("tool equipped")
if key == Enum.KeyCode.F then
print("pressed f")
script.Fire:FireServer()
print("fired server")
end
end
end
end)
Everytime I test the tool, it only prints the “tool equipped” - not anything else.
I don’t know what’s wrong with the code. I want for the remote event to fire everytime the player presses F while the tool is equipped.
local tool = script.Parent
local equipped = false
local UID = game:GetService("UserInputService")
tool.Equipped:Connect(function()
equipped = true
end)
tool.Unequipped:Connect(function()
equipped = false
end)
UID.InputBegan:Connect(function(key,isTyping)
if isTyping == false then
if equipped == true then
print("tool equipped")
if key.KeyCode == Enum.KeyCode.F then
print("pressed f")
script.Fire:FireServer()
print("fired server")
end
end
end
end)