Currently whenever I press e it runs the script but I only want it to run when the tool is equipped
local tool = script.Parent local uis = game:GetService("UserInputService") local rs = game:GetService("ReplicatedStorage") local Nogr = rs.nogr tool.Equipped:Connect(function() uis.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.E then Nogr:FireServer() end end) end)
local tool ,equipped= script.Parent,false local uis = game:GetService("UserInputService") local rs = game:FindService("ReplicatedStorage") local Nogr = rs:WaitForChild"nogr" tool.Equipped:Connect(function()equipped=true;end) tool.Unequipped:Connect(function()equipped=false;end) uis.InputBegan:Connect(function(input)if not equipped then return end if input.KeyCode == Enum.KeyCode.E then Nogr:FireServer() end end)
im not the answer-er (lol) but i'll try to explain the code
local tool ,equipped= script.Parent,false --equipped is used as a debounce here local uis = game:GetService("UserInputService") --getting userinputservice to detect input local rs = game:FindService("ReplicatedStorage") --self explanatory local Nogr = rs:WaitForChild"nogr" --self explanatory tool.Equipped:Connect(function()equipped=true;end) --the variable equipped becomes true if the tool is equipped tool.Unequipped:Connect(function()equipped=false;end) --the variable equipped becomes false if the tool is unequipped uis.InputBegan:Connect(function(input)if not equipped then return end --code ends if equipped is false if input.KeyCode == Enum.KeyCode.E then --if the user pressed 'E' Nogr:FireServer() --fires the remote event end end)