Function connection not working?

Am I doing something wrong with setting this connection? I know that something’s going wrong with the connection = funct() line because the last if statement doesn’t run.

local connection

local function func()
-- the stuff in here continues to run AFTER being disconnected
while wait(.1) do
remote:FireServer()
end
end

spawn(function()
	connection = func()
end)

wait(3)

if connection ~= nil then
	func:Disconnect()
end
1 Like

in short, by putting “while” you will not be able to pass another code until that loop ends

1 Like

I don’t really know what you’re trying to do but I’m pretty sure you’re supposed to do connection:Disconnect() and not func:Disconnect()

1 Like
local connection

local function call()
remote:FireServer()
end

spawn(function()
while wait() do
	connection = func()
	wait(3)
	if connection ~= nil then
		print("inactive")
		break
	end
end)

idk if this works