The script pauses?

My server event code seems to work fine upto some point but it will pause at one line and then resume a few seconds later???

:UnionAsync() seems to be causing the problems

I tried looking it up on google, no results concerning my problem.


replicatedStorage.DrawingFinish.OnServerEvent:Connect(function(player, drawingData)
	local playerCar = player.PlayerCar.Value
	local back_Wheel1 = playerCar.backWheel1
	local back_WheelCFrame = back_Wheel1.CFrame
	
	local object = {}
	for i,v in drawingData do
		print('Lookping through drawing data......... ' .. tostring(i))
		table.insert(object, Instance_Parts(v, playerCar.backWheel1))
	end
	print('FInished looping')
	local wheel = back_Wheel1:UnionAsync(object)
	print('Made a uniom')
	wheel.Parent = playerCar
	print('Put it in the car')
	wheel.CFrame = back_WheelCFrame
	print("Set the cframe")
	back_Wheel1:Destroy()
	print('Union event ended')
	for i,v in object do
		v:Destroy()
	end
end)

everything upto print(‘FInished looping’) runs fine, it prints it out, the Instance_Parts function works properly.
Then it pauses for a few seconds to then continue on with the script.
Script is located in serer script service

:UnionAsync() yields the thread until it is completed, which is why the script pauses.

I also recommend wrapping it into a pcall in case it fails so it won’t break the entire script.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.