Problem while setting transparency in a while true do loop

So, i’m trying to make a laser that makes you dissapear completely with effects, the laser itself works but when the value is set to false the loop wont break and i don’t know why, here is the code, keep in mind that i defined the values

	while teleport.Value == true do
		if player.Character.Torso.Transparency ~= 0 then
			wait(10)
			teleport.Value = false
			break
		end
		for _,v in pairs(player.Character:GetDescendants()) do
			if v:IsA("Part") and v.Name ~= "HumanoidRootPart" then
				v.BrickColor = BrickColor.new("Cyan")
				v.Material = Enum.Material.ForceField
				v.Transparency = v.Transparency + 0.01
				if v.Transparency == 1 then
					teleport.Value = false
				end
			end
			
			if v:IsA("Decal") then
				v:Destroy()
			end
		end
		wait()
	end
	player.Character:WaitForChild("hit"):Destroy()
	player.Character:WaitForChild("target"):Destroy()

Transparency might not be hitting exactly 1 because of floating point issues is a possibility… but I don’t think that’s what’s happening here.

Can you show me the rest of the script? Also the bit where you have a 10 second weight looks really strange to me, what’s that for?

1 Like

the 10 second delay was an attempt to fix the transparency issue, when the transparency started changing, it would wait 10 seconds and then check the value as false

That was an error, i deleted it already

script.Parent.l.MouseClick:Connect(function(player)
	local weld = Instance.new("Weld")
	local laser = game:GetService("ReplicatedStorage").target:Clone()
	local hiteffect = game:GetService("ReplicatedStorage").woosh.hit:Clone()
	local TweenService = game:GetService("TweenService") 
	local tweenPart = game.Workspace.conspiracy
	local teleport = player.Character:WaitForChild("teleport")

	local info = TweenInfo.new(7,Enum.EasingStyle.Linear,Enum.EasingDirection.InOut,0,false,0)

	local Goals = {Position = Vector3.new(50.092, 37.64, -19.28),Orientation = Vector3.new(-89.38, 0, 0)}
	
	

	local Tween = TweenService:Create(tweenPart, info, Goals)
	 
	
	Tween:Play()
	workspace["Hydraulic Lift Sound Effect"]:Play()
	wait(7)
	teleport.Value = true
	laser.Parent = player.Character
	laser.Position = player.Character:WaitForChild("Torso").Position
	weld.Parent = laser
	weld.Part0 = laser
	weld.Part1 = player.Character:WaitForChild("Torso")
	for _, v in workspace.origin:GetDescendants() do
		if v:IsA("Beam") then
			v.Enabled = true
			v.Attachment1 = laser:WaitForChild("laseeer")
		end
	end
	hiteffect.Parent = player.Character:WaitForChild("Torso")
	laser:WaitForChild("Blocksworld Laser Beam"):Play()
	laser:WaitForChild("Blocksworld Laser Beam").Looped = true
	while teleport.Value == true do
		if player.Character.Torso.Transparency ~= 0 then
			wait(10)
			teleport.Value = false
			break
		end
		for _,v in pairs(player.Character:GetDescendants()) do
			if v:IsA("Part") and v.Name ~= "HumanoidRootPart" then
				v.BrickColor = BrickColor.new("Cyan")
				v.Material = Enum.Material.ForceField
				v.Transparency = v.Transparency + 0.01
			end
			
			if v:IsA("Decal") then
				v:Destroy()
			end
		end
		wait()
	end
	player.Character:WaitForChild("hit"):Destroy()
	player.Character:WaitForChild("target"):Destroy()
end)

what if you tween the transparency to 1 and then break the loop after the tweens are done

the tweens are for something else.

I’m not seeing any reason why after that 10 second wait, the loop wouldn’t break. Are there any other scripts that are changing teleport.Value?

No, there arent
(text to shooooooooooooooort)

Can you put a print right after the whole loop starts, that is: print(“While loop running:”,teleport.Value)

Then, can you put another print after the end of that loop, that is: print(“While loop ended”)

I often use prints for debugging when things get more complicated. You can run the code, and see what all the output makes. I’d recommend chancing that 10 second wait to 1 second though, so that it doesn’t take so long to complete. I want to see what the output is like, if you run it, and it it ever prints the “ended” print.

Im gonna try that.
(text too short)

So, i figured out that the issue wasnt in the while loop, it was the lines that followed after finishing it, then i figured out that i referenced the laser wrong.

I’m still marking this post as a solution because without it i wouldnt of have found out about the
real issue, i will use this technique when i run into further issues.

1 Like