How Do I fix this while loop

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve?
    Im trying to fix this while loop but I can’t find A way around it

  2. What is the issue? Include screenshots / videos if possible!

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I’ve tried to use a coroutine wrap but it gave the same result and I did multiple searches and couldn’t find anything that worked

3 Likes

Where’s your code?

1 Like
local Fire = script.Parent.Parent.MenuScreen.AbilitySelect.Fire.TextButton
Fire.Active = false
Fire.MouseButton1Click:Connect(function()
	local StuffFrame = script.Parent.Parent.MenuScreen.StuffMenuFrame
	script.Parent.Parent.MenuScreen.AbilitySelect.Visible = false
	TweenService:Create(StuffFrame, TweeninfoGui, {Position = UDim2.new(-0.163, 0,0.362, 0)}):Play()
	plr:SetAttribute("FireMagic", true)
	plr:SetAttribute("AbilitySelected", true)
end)

local function HasFire()
	while plr:GetAttribute("FireMagic") and plr:GetAttribute("AbilitySelected") do
	local MenuScreen = script.Parent.Parent.MenuScreen
	local Stuff = script.Parent.Parent.MenuScreen.StuffMenuFrame
		local MenuFire1 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(255, 142, 28)})
		local MenuFire2 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(255, 142, 28)})
		MenuFire1:Play()
		MenuFire2:Play()
		wait(5)
		local MenuFire3 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(172, 95, 19)})
		local MenuFire4 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(255, 142, 28)})
		MenuFire3:Play()
		MenuFire4:Play()
		wait(5)
	end
end

local Wind = script.Parent.Parent.MenuScreen.AbilitySelect.Wind.TextButton
Wind.Active = false
Wind.MouseButton1Click:Connect(function()
	local StuffFrame = script.Parent.Parent.MenuScreen.StuffMenuFrame
	script.Parent.Parent.MenuScreen.AbilitySelect.Visible = false
	TweenService:Create(StuffFrame, TweeninfoGui, {Position = UDim2.new(-0.163, 0,0.362, 0)}):Play()
	plr:SetAttribute("WindMagic", true)
	plr:SetAttribute("AbilitySelected", true)
end)

local function HasWind()
	while plr:GetAttribute("WindMagic") and plr:GetAttribute("AbilitySelected") do
		local MenuScreen = script.Parent.Parent.MenuScreen
		local Stuff = script.Parent.Parent.MenuScreen.StuffMenuFrame
		local MenuFire1 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(28, 255, 149)})
		local MenuFire2 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(28, 255, 149)})
		MenuFire1:Play()
		MenuFire2:Play()
		wait(5)
		local MenuFire3 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(2, 57, 31)})
		local MenuFire4 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(2, 57, 31)})
		MenuFire3:Play()
		MenuFire4:Play()
		wait(5)
	end
end

local Earth = script.Parent.Parent.MenuScreen.AbilitySelect.Earth.TextButton
Earth.Active = false
Earth.MouseButton1Click:Connect(function()
	local StuffFrame = script.Parent.Parent.MenuScreen.StuffMenuFrame
	script.Parent.Parent.MenuScreen.AbilitySelect.Visible = false
	TweenService:Create(StuffFrame, TweeninfoGui, {Position = UDim2.new(-0.163, 0,0.362, 0)}):Play()
	plr:SetAttribute("EarthMagic", true)
	plr:SetAttribute("AbilitySelected", true)
end)

local function HasEarth()
	while plr:GetAttribute("EarthMagic") and plr:GetAttribute("AbilitySelected") do
		local MenuScreen = script.Parent.Parent.MenuScreen
		local Stuff = script.Parent.Parent.MenuScreen.StuffMenuFrame
		local MenuFire1 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(230, 221, 93)})
		local MenuFire2 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(230, 221, 93)})
		MenuFire1:Play()
		MenuFire2:Play()
		wait(5)
		local MenuFire3 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(140, 140, 24)})
		local MenuFire4 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(140, 140, 24)})
		MenuFire3:Play()
		MenuFire4:Play()
		wait(5)
	end
end

local Ice = script.Parent.Parent.MenuScreen.AbilitySelect.Ice.TextButton
Ice.Active = false
Ice.MouseButton1Click:Connect(function()
	local StuffFrame = script.Parent.Parent.MenuScreen.StuffMenuFrame
	script.Parent.Parent.MenuScreen.AbilitySelect.Visible = false
	TweenService:Create(StuffFrame, TweeninfoGui, {Position = UDim2.new(-0.163, 0,0.362, 0)}):Play()
	plr:SetAttribute("IceMagic", true)
	plr:SetAttribute("AbilitySelected", true)
end)

local function HasIce()
	while plr:GetAttribute("IceMagic") and plr:GetAttribute("AbilitySelected") do
		local MenuScreen = script.Parent.Parent.MenuScreen
		local Stuff = script.Parent.Parent.MenuScreen.StuffMenuFrame
		local MenuFire1 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(44, 206, 255)})
		local MenuFire2 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(44, 206, 255)})
		MenuFire1:Play()
		MenuFire2:Play()
		wait(5)
		local MenuFire3 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(10, 95, 124)})
		local MenuFire4 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(10, 95, 124)})
		MenuFire3:Play()
		MenuFire4:Play()
		wait(5)
	end
end

local Thunder = script.Parent.Parent.MenuScreen.AbilitySelect.Thunder.TextButton
Thunder.Active = false
Thunder.MouseButton1Click:Connect(function()
	local StuffFrame = script.Parent.Parent.MenuScreen.StuffMenuFrame
	script.Parent.Parent.MenuScreen.AbilitySelect.Visible = false
	TweenService:Create(StuffFrame, TweeninfoGui, {Position = UDim2.new(-0.163, 0,0.362, 0)}):Play()
	plr:SetAttribute("ThunderMagic", true)
	plr:SetAttribute("AbilitySelected", true)
end)
local function HasThunder()
	while plr:GetAttribute("ThunderMagic") and plr:GetAttribute("AbilitySelected") do
		local MenuScreen = script.Parent.Parent.MenuScreen
		local Stuff = script.Parent.Parent.MenuScreen.StuffMenuFrame
		local MenuFire1 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(157, 35, 198)})
		local MenuFire2 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(157, 35, 198)})
		MenuFire1:Play()
		MenuFire2:Play()
		wait(5)
		local MenuFire3 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(51, 7, 83)})
		local MenuFire4 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(51, 7, 83)})
		MenuFire3:Play()
		MenuFire4:Play()
		wait(5)
	end
end

local Water = script.Parent.Parent.MenuScreen.AbilitySelect.Water.TextButton
Water.Active = false
Water.MouseButton1Click:Connect(function()
	local StuffFrame = script.Parent.Parent.MenuScreen.StuffMenuFrame
	script.Parent.Parent.MenuScreen.AbilitySelect.Visible = false
	TweenService:Create(StuffFrame, TweeninfoGui, {Position = UDim2.new(-0.163, 0,0.362, 0)}):Play()
	plr:SetAttribute("WaterMagic", true)
	plr:SetAttribute("AbilitySelected", true)
end)

local function HasWater()
	while plr:GetAttribute("WaterMagic") and plr:GetAttribute("AbilitySelected") do
		local MenuScreen = script.Parent.Parent.MenuScreen
		local Stuff = script.Parent.Parent.MenuScreen.StuffMenuFrame
		local MenuFire1 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(49, 78, 223)})
		local MenuFire2 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(49, 78, 223)})
		MenuFire1:Play()
		MenuFire2:Play()
		wait(5)
		local MenuFire3 = TweenService:Create(MenuScreen, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(32, 87, 176)})
		local MenuFire4 = TweenService:Create(Stuff, TweeninfoMenu, {BackgroundColor3  = Color3.fromRGB(32, 87, 176)})
		MenuFire3:Play()
		MenuFire4:Play()
		wait(5)
	end
end

local function Check()
	while true do
	HasIce()
	HasWater()
	HasEarth()
	HasWind()
	HasFire()
	HasThunder()
	wait(1)
	print("Attributes Checked")
	end
end

Check()
2 Likes

This is just the part i Used for the loop

1 Like

Show your output, and also print checks in each function to ensure each function is passing correctly.


each function is passing im printing the function which is hasFire, hasIce, etc

What exactly are you trying to fix? It seems the loop keeps running until you select the button. Is this not the desired outcome?

1 Like

It is the desired out come but when I press the button the gui or StuffFrame Doesn’t come back to its position and I thought it was because of the loop

2 Likes