How do i fix "attempt to compare nil and number"

Im making a skill system and im not sure whats wrong in this script, can anyone tell me?

local EventE = game:GetService("ReplicatedStorage").Events.EventE
game:GetService("Players").PlayerAdded:Connect(function(player)
	local cooldown = Instance.new("NumberValue")
	cooldown.Value = tick()
	cooldown.Name = "Cooldown"
	cooldown.Parent = player
end)

EventE.OnServerEvent:Connect(function(player, cooldown)
	if tick() - player.Cooldown.Value > cooldown then
		--Here we will put tje actual ability code
		player.Cooldown.Value = tick()
	end
end)

Thank you

You’re attempting to compare something that’s non-existent (Or something that isn’t visible to the server)

You should probably print what cooldown.Value actually is or tick()

im not sure what you mean

local EventE = game:GetService("ReplicatedStorage").Events.EventE
game:GetService("Players").PlayerAdded:Connect(function(player)
	local cooldown = Instance.new("NumberValue")
	cooldown.Value = tick()
    print("Cooldown's Value: "..cooldown.Value)
	cooldown.Name = "Cooldown"
	cooldown.Parent = player
end)

EventE.OnServerEvent:Connect(function(player, cooldown)
    print(cooldown)
	if tick() - player.Cooldown.Value > cooldown then
		--Here we will put tje actual ability code
		player.Cooldown.Value = tick()
	end
end)

Just try this and see what Outputs back

"Cooldown’s Value: 1615489017.0516 "

Try & fire the RemoteEvent as well, cause that’s where the error lies

i already fired a remote event in another scrpt
Heres the script

local UIS = game:GetService("UserInputService")
local hotkey = Enum.KeyCode.E
local cooldown = 5
local event = game:GetService("ReplicatedStorage").Events.EventE

local player = game:GetService("Players").LocalPlayer

UIS.InputBegan:Connect(function(input)
	if input.KeyCode == hotkey then
		if tick() - player.Cooldown.Value > cooldown then
			event:FireServer()
		end
	end
end)

Ok RIP I see the issue

You didn’t pass any arguments onto this event from the client side, change that to

event:FireServer(cooldown)

LOL , my bad thanks for helping

1 Like

You should probably go over your scripts a little better next time xD

1 Like