Making a script that activates a sword if you press it the first time and destroys the sword if you press it the second time. However, when I press the key, both events run at the same time even though I set a variable (equipped = false). The sword script works btw, its just the keyboard input Please check this out, thanks!
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorage:WaitForChild("Activate")
local Event2 = ReplicatedStorage:WaitForChild("Destroy")
local equipped = false
function onKeyPress(inputObject, gameProcessedEvent)
if inputObject.KeyCode == Enum.KeyCode.F and equipped == false then
wait()
equipped = true
warn("Activate")
Event:FireServer()
end
if inputObject.KeyCode == Enum.KeyCode.F and equipped == true then
wait()
equipped = false
warn("Destroy")
Event2:FireServer()
end
end
game:GetService("UserInputService").InputBegan:connect(onKeyPress)