Player part is still a value even when the player is :LoadCharacter() again

guys rn Im encounter a bug that when I fire the binary event with the character model of a player, when I use :LoadCharacter on that player I want the while loop that to stop by checking if the value emit part is nil but when I play it the while loop still continue even when I use :LoadCharacter() and the value emit is still not nil

Event.NoobHead.Event:Connect(function(Char)
	local EmitPart = Char.Head:WaitForChild("EmitPart")
	local Speed = 0.1
	
	while wait(Speed) and EmitPart ~= nil do
		--do the stuff with emit part
	end
end)
4 Likes

I guess what you want is to close the loop when the emit part is destroyed,
Well what actually happens when we destroy an object Is that its all properties gets locked and its parent is set to nil, this is because if a variable still holds that position of object in memory and performs to do something with it, the program will crash. so you may wanna do this:

while wait(Speed) and EmitPart.Parent ~= nil do
		--do the stuff with emit part
	end

I had tried to print the emit part, even when the player is reload the emit part is still isn’t nil

If you are not comfortable in English, please use a translator to translate from your language to English, I cant understand what you are trying to say.

Try this.

Event.NoobHead.Event:Connect(function(Char)
	local EmitPart = Char.Head:WaitForChild("EmitPart")
	local Speed = 0.1
	
	while task.wait(Speed) do
		if EmitPart ~= nil then
		   --do the stuff with emit part
		end
	end
end)

nah it, the emit part value is still not nil even when the character is reloaded, I had try to check it’s parent which is the workspace and it work now

Mark your own comment as the solution then if the solution has been found

2 Likes

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