Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Gui keeps appearing even though I break the loop?

Hello there. I'm trying to make a local script so that whenever a player enters a house, a gui will show whose house it is.

local houseRegions = game.Workspace:WaitForChild("HouseRegions")

local found = false

while wait(1) do
	for i, v in pairs(houseRegions:GetChildren()) do
		found = false
		
		local region = Region3.new(v.Position - (v.Size/2), v.Position + (v.Size/2))
		local parts = workspace:FindPartsInRegion3WithWhiteList(region, game.Players.LocalPlayer.Character:GetDescendants())
		
		for _, part in pairs(parts) do
			if part:FindFirstAncestor(game.Players.LocalPlayer.Name) then
				found = true
				break
			else
				found = false
			end
		end
		
		if found then
			if script.Parent.HouseRegions[v.Name] then
				script.Parent.House.TextLabel.Text = script.Parent.HouseRegions[v.Name].Value -- it's a string value stored inside a folder called HouseRegions in the starterGui.
				script.Parent.House.TextLabel.Visible = true
				
				for i = 1, 0, -0.1 do
					script.Parent.House.TextLabel.TextTransparency = i
					wait(0.05)
				end
				
				wait(1)
				
				for i = 0, 1, 0.1 do
					script.Parent.House.TextLabel.TextTransparency = i
					wait(0.05)
				end
				
				script.Parent.House.TextLabel.Visible = false
				
				break
			end
		else
			script.Parent.House.TextLabel.Text = script.Parent.Mapleburg.Value -- string value
			script.Parent.House.TextLabel.Visible = true
			
			for i = 1, 0, -0.1 do
				script.Parent.House.TextLabel.TextTransparency = i
				wait(0.05)
			end
			
			wait(1)
			
			for i = 0, 1, 0.1 do
				script.Parent.House.TextLabel.TextTransparency = i
				wait(0.05)
			end
			
			script.Parent.House.TextLabel.Visible = false
		end
	end
end

Everything seems to be working, but the gui that indicates the stuff keeps appearing. (yes I've tried a replica of alvinblox's region3 tutorial.)

3 comments

0

Your only breaking the for loop, not the while wait loop

0

Which line is it?

0

it's not an error. the script works fine but the screengui keeps appearing even though i break the for loop.

2 answers

Try making it a while [randomval] == true do and when you want it to stop, make the value to false.

local myval = true
local num = 0
while myval == true do
	num = num + 1
	print(num)
	if num == 10 then
		myval = false
	end
end

1 comment

0

it wouldn't work if i do that either.

Found a solution, even though I had to rewrite the whole script.

This discussion is preserved as it was. New answers, comments, and votes are closed.