Script Works Perfectly fine its just it would start to "hold" the key down if the player types whilst holding down the key
local player = game:GetService("Players").LocalPlayer
local UseEvent = script.Parent:WaitForChild("Amaterasu")
local DeactivateEvent = script.Parent:WaitForChild("Stop")
local Key = "C"
local startHoldingTime = tick() -- time when the player started holding. tick() is the current time
local expectedHoldTime = 7 -- How long you want the player to be hold the key for
local isBeingUsed = false
-- runs whenever the player presses a key
game:GetService("UserInputService").InputBegan:Connect(function(Input, gameProcessed)
if gameProcessed then return end -- stops this event from firing if we're typing / roblox is using the keys in some way
if Input.KeyCode == Enum.KeyCode[Key] then
startHoldingTime = tick()
end
end)
--runs whenever the player stops pressing a key
game:GetService("UserInputService").InputEnded:Connect(function(Input, gameProcessed)
if gameProcessed then return end -- stops this event from firing if we're typing / roblox is using the keys in some way
local timeHeldDown = tick() - startHoldingTime --how long the player held down the button in seconds
if Input.KeyCode == Enum.KeyCode[Key] then
print(player.Name..' holded '..Key..' for '.. timeHeldDown ..' second(s).')
--if the player is using the mode already, fire the deactivate event
if isBeingUsed then
print("Firing the deactivate event!")
DeactivateEvent:FireServer()
isBeingUsed = false
--if the player HASN'T used the mode yet, check if they held the key long enough to use the mode
else
if timeHeldDown >= expectedHoldTime then
print("Firing the used event!")
isBeingUsed = true
UseEvent:FireServer()
else
print("player didn't hold key for long enough to fire any events. ")
end
end
end
end)
