Even with assistance it still seems to not work what am i doing wrong?
local PlayerService = game:GetService("Players")
local UserInputService = game:GetService("UserInputService") -- Using UserInputService instead of mouse.
local Client = PlayerService.LocalPlayer
local Key = "M" -- The ke the person has to hold
local Holding = false -- Detects when the key is being held
local ExpectedHold = 3 -- How long you want the player to be hold the key for
local HoldingTime = 0 -- The amount of seconds they holded for
local Event = game.ReplicatedStorage:WaitForChild("Use")
UserInputService.InputBegan:Connect(function(Input, GPE)
if not GPE then
if Input.KeyCode == Enum.KeyCode[Key] then -- When they start to press the key this runs
if not Holding then -- if they arent already holding then it continues
Holding = true -- Makes holding true/script now knows they're holding the key
while Holding do wait(1) -- Basically while holding == true the code after this will run every second
if HoldingTime < ExpectedHold then
HoldingTime = HoldingTime + 1 -- This adds to how long they holder the key for
end
end
end
end
end
end)
UserInputService.InputEnded:Connect(function(Input, GPE) -- runs when they stop holding a key
if not GPE then
if Input.KeyCode == Enum.KeyCode[Key] then
if HoldingTime >= ExpectedHold then -- if they holding the key for the right amount of time
Event:FireServer() -- fires the remote if they did
else
print(Client.Name..' holded '..Key..' for '..HoldingTime..' second(s).')
HoldingTime = 0 -- sets the time back to 0
end
end
end
end)

5 comments
Do you want the event to be able to fire while they're still holding the key down if it's over ExpectedHold, or only once they release the key?
Yeah while they are still holding down the key
@vector3_zero The script works like this. While they're holding down the key it detects how long they've held it for. Once they release, if it's greater than ExpectedHold it fires the remote
I Fixed this issue thanks!
I got the script working but now i can't deactivate it after once fired