While task.wait loop breaks entire script

  1. What do you want to achieve? loop check if a player has stringvalue inside them before and whilst touching part

  2. What is the issue? Background transparency and animation DOES NOT stop when player gets stringvalue mid way through (or insidepart)

  3. What solutions have you tried so far? Tried everything

Here is my script, it is local ofcourse (StarterCharacter)

while task.wait(0.05) and not parent:FindFirstChild("Morphed") and not parent:FindFirstChild("Immune")  do
	function onTouchEnded(part)
	local player = getPlayerFromRootPart(part)
	if not player then return end
	local index = table.find(playersTouching, player)
	if not index then return end 
	table.remove(playersTouching, index)
	local moprhed = parent:FindFirstChild("Morphed")
	if moprhed == nil then
		tween:Cancel()
		anim:Stop()
		task.wait(0.1)
			TweenService:Create(frame, TweenInfo.new(0.5), {Transparency = 1}):Play()
		print("Exited", player)
		end
end
end
2 Likes

Update: managed to find the solution by myself by putting while loop outside the function and using anim.IsPlaying then stopping.