#(SOLVED)Loop control error

1 messages · Page 1 of 1 (latest)

brave plinth
#
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

midnight lagoon
#

do taskToControl = task.create(addXP, player)

brave plinth
#

Let me try

#

There is no task.create

#

But it worked with task.spawn

#

@midnight lagoon tysm

#

(SOLVED)Loop control error