local function addXP(player)
while true do
print("adding")
wait(0.5)
end
end
local NeedToAdd = false
local taskToControl = nil
local function switchForAdding(player, needToAdd)
NeedToAdd = needToAdd
if NeedToAdd then
if taskToControl then
task.cancel(taskToControl)
end
taskToControl = task.defer(addXP(player))
else
task.cancel(taskToControl)
end
end
addXPForStepRemoteEvent.OnServerEvent:Connect(switchForAdding)
I cant cancel the existing task can you help me please?
also when I try to cancel it, it says that "thread expected, got nil" is nil