Hi everyone,
So i’m stuck on a script for few hours now, and I just cannot fix it.
I really need help.
This is my code
i’m trying to make it so the RemoteEvent gets fired when the key is released, but instead, it gives me this error.
Client:95: attempt to compare nil <= number - Client - Client:95
The line 95 is this line:
if CurrentTime >= (ReleaseTimes[Input.KeyCode.Value]) then
I appreciate any help ![]()
local RS = game:GetService("ReplicatedStorage")
local TS = game:GetService("TweenService")
local UIS = game:GetService("UserInputService")
local PLRS = game:GetService("Players")
--------------------------------------------------------------------------- CONFIG
local Cooldowns = {
Keybind1 = 8,
Keybind2 = 10,
Keybind3 = 13,
Keybind4 = 3,
Keybind5 = 0,
}
local LevelRequired = {
Keybind1 = 1,
Keybind2 = 25,
Keybind3 = 50,
Keybind4 = 10,
Keybind5 = 0,
}
--------------------------------------------------------------------------- VARIABLES
local Player = PLRS.LocalPlayer
local Level = Player:WaitForChild("leaderstats"):WaitForChild("Level")
local Character = Player.Character or Player.CharacterAdded:Wait()
local Values = RS:WaitForChild("Values")
local Keybinds = Values:WaitForChild("Keybinds")
local RemoteEvent = script.Parent:WaitForChild("RemoteEvent")
local Tool = script.Parent
local MovesGUI
local Equipped = false
local HoldingKeys = {}
local ReleaseTimes = {}
--------------------------------------------------------------------------- UIS
local function DetectInput(Key, LevelRequired)
if Level.Value < LevelRequired then return end
local CurrentTime = tick()
if not HoldingKeys[Key.Value] or CurrentTime - HoldingKeys[Key.Value] >= Cooldowns[Key.Name] then
ReleaseTimes[Key.Value] = CurrentTime + Cooldowns[Key.Name]
return true
else
return false
end
end
local function FireRemoteEvent(Key)
if Level.Value >= LevelRequired[Key.Name] then
print(Key.Value.." is released.")
RemoteEvent:FireServer(Key.Value, LevelRequired[Key.Name])
HoldingKeys[Key.Value] = nil
ReleaseTimes[Key.Value] = nil
if MovesGUI and MovesGUI:WaitForChild("Frame"):FindFirstChild(Key.Name) then
local CooldownFrame = MovesGUI:WaitForChild("Frame"):WaitForChild(Key.Name):WaitForChild("Cooldown")
CooldownFrame.BackgroundTransparency = 1
end
end
end
local function FindKeybindByValue(value)
for _, Child in ipairs(Keybinds:GetChildren()) do
if Child:IsA("StringValue") then
if Child.Value == value then
return Child
end
end
end
return nil
end
UIS.InputBegan:Connect(function(Input, Typing)
if Typing then return end
if Character:WaitForChild("Values"):WaitForChild("CanAttack").Value == false then return end
if not Equipped then return end
if Input.KeyCode == Enum.KeyCode.Unknown then return end
local Key = FindKeybindByValue(UIS:GetStringForKeyCode(Input.KeyCode))
if Key then
if DetectInput(Key, LevelRequired[Key.Name]) then
print(Key.Value .. " is pressed.")
HoldingKeys[Input.KeyCode.Value] = tick()
end
end
end)
UIS.InputEnded:Connect(function(Input)
local Key = FindKeybindByValue(UIS:GetStringForKeyCode(Input.KeyCode))
if Key and HoldingKeys[Input.KeyCode.Value] then
local CurrentTime = tick()
if CurrentTime >= (ReleaseTimes[Input.KeyCode.Value]) then
FireRemoteEvent(Key)
end
end
HoldingKeys[Input.KeyCode.Value] = nil
end)