Module script is slowing down

i have a build system and when you spam 2 diffrent blocks fast the module script will start to slow down/lag/delay

originaly i thought it was bc the debounce is local so you are spamming the module script too much causing it to lag but then i made the block debounce global and it still lags when you spam 1 and 2 and auto click

External Media

as you can see after spamming 1 and 2 the module script starts to become delayed and slow

1 Like

Does it have something to do with the memory being used? with creating all those instances and the placeholder block while hovering is it possible there is a data leak in your code? this would account for lag etc. Check to see if you are properly destroying unused parts. Also it might be useful to show some of your code so we can solve this problem.

how would i check if their is a data leak and how do you properly delete a item,

and here is some code that i think might be causing the lag

--client
script.Parent.Parent.Activated:Connect(function() -- Self explanitory
	if _G.Debounce ==  false then
		_G.Debounce = true
		spawn(function()
			BuildModule:Build((string.split(script.Parent.Parent.Name, " "))[1])
		end)
		wait(0.033)
		_G.Debounce = false
	end

end)




spawn(function()
	tool.Equipped:Connect(function()
		if _G.OutlineDebounce == false then
			BuildModule:Outline()
			wait(0.1)
			_G.OutlineDebounce = true
		end
	end)
end)

--module (part of the deleting and making the place holder)


					spawn(function()
						local Block = game.ReplicatedStorage.Blocks.Outline:Clone()

						Block.Parent = workspace

						Block:SetPrimaryPartCFrame(CFrame.new(MousePosX, MousePosY + 0.5, MousePosZ))

						wait(0.05)
						Block:Destroy()



					end)


hmmm I’m not sure how to tell for certain but If you notice, by the end of the video the black frame which Im assuming to be the placeholder for the black has about 10 copies at once, and starts to take longer to delete. I would think it has something to do with spawn and the wait’s, though I’m not certain. I am not the best programmer, but I’d say take a look into that

1 Like

the problem was that once u equipt the block and unequipted it, it never stopped placing the outline so after opening and closing the block 20 times its running 20 times

1 Like

ok sweet, if you wanna give me the solution haha!

you have the solution! :DDDDDDDDDDDDDDD

1 Like

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