Even With The parent being nil the model can affect the game performance?

I am creating a button system that whonever the button is used the script will define the button parent as nil,

My doubt is, even the button parent being nil the game will still render it? if there’s too many buttons as parent = nil the performance will be affected or it’s like the Destroy function?

1 Like

Parenting a part to game might not connect to internal connection. so i recomanded you use :Destroy().

2 Likes

I don’t use Destroy because I use 2 function to buy and the two set the used attribute has true so if I use destroy i’m afraid the game will only execute one function and delete the script before execute the other.

1 Like

wrapping your function in a new thread may prevent it from being stopped from executing.

2 Likes

I’m Trying this now but the coroutine simply doesn’t work, it gives the error ServerScriptService.Components.Buttons:124: missing argument #1 to 'wrap' (function expected)

here’s part of the moduleScript

function Buttons:waitanddestroy(Button)
	task.wait(3)
	Button:Destroy()
end
	
	
	
	
	
function Buttons:Sell()
	
	for _, Button in ipairs (CollectionService:GetTagged("Button")) do
		
		if Button:GetAttribute("Used") == true
		then 
			Button.Parent = game:GetService("ReplicatedStorage")
		    coroutine.wrap(Buttons:waitanddestroy(Button))()
					
			end	end
		end		

1 Like

What if you set the button’s parent to a folder inside of ServerStorage?

2 Likes

im taking about task.spawn, its simpler than coroutine

2 Likes

It will affect the performance ?

1 Like

If youre talking about performance as in Frames per Second, anything that isnt parented to workspace, or an active ViewportFrame will not be rendered.

If the models are no longer needed, you are better off deleting them, however, if the model is a map for your game, changing its parent to ServerStorage or ReplicatedStorage will stop it from being rendered, therefore keeping the frames up.

2 Likes

I used task.spawn(Buttons:waitanddedtroy(Button))
And it returns a similar error

1 Like

No i mean on the function you’ll be executing once the button is suppose to be parented to nil

2 Likes

Well I can’t use Destroy directly, I need to add a wait but corountine.wrap and task.spawn doen’t work so if changes the parente don’t give any performance error I will only set the parent as nil.

1 Like

the coroutine doesnt work because you formatted it incorrectly.

coroutine.wrap(Buttons:waitanddestroy)(Button)
2 Likes

Yes, it’s the same function but i changed nil to replicatedStorage because I can see if the button is still there.

1 Like

Now it’s blue

Captura de tela 2022-09-17 151512

1 Like

Attempt renaming the function to Buttons_Wait_and_Destroy
However, if Buttons is a module script, i dont know if you can coroutine a function in one, since i dont really use module scripts.

2 Likes

that’s can be the problem, It’s a ModuleScript

1 Like

Just did some testing, and yes, you can coroutine functions in module scripts.
Screenshot (668)
Screenshot (670)
Screenshot (669)

1 Like

so I don’t know why isn’t working

1 Like

Im not entirely sure how functions work in module scripts, however the formatting i used worked perfectly fine.

If you can, just try doing coroutine.wrap(module.waitanddestroy)(Button)
Im not sure if that will work though.

2 Likes