I'm trying to make a SurfaceGUI with a GUI, which are linked, you press a button in the gui which changes a value, That works.
What I'm trying to do now is have the surface gui display one of two phases. Custom Messages, or looped messages.
local nextMsg = 20 local titles = { --Titles "Need Help?"; "REMEMBER:"; "REMEMBER:"; } local title = script.Parent.Title local cont = script.Parent.Content local content = { --The content "Use the 911 callbox to get help!"; "Stick to the speed limit! People are trying not to get hurt!"; "Trespassing is a crime! Trespassing on other's properties will get you arrested!"; } math.randomseed(os.time()) local emergency = workspace.CMessages.Value while wait() do if emergency == false then for i, r in ipairs(titles) do title.Text = titles[i]; cont.Text = content[i]; wait(nextMsg) end elseif emergency == true then title.Text = "Park Emergency" cont.Text = game.Workspace.CMessages.EMessage.Value end end
The question for those who don't understand
How do I get this to work, because when I change the value to true, it changes, but when I change it to false, it doesn't go back to the looping. Why?
Your emergency variable was being set outside of the while loop. While the while loop was running, the value could never be changed.
I have modified the script to use the .Changed
event since it is a more efficient way of checking if a value has changed rather than a while loop. Every time the Changed event is fired the script will provide the bool value. The script will go through the if statement and will make the necessary changes. I removed the math.randomseed()
function since you never used math.random()
in your script.
local nextMsg = 20 local titles = { --Titles "Need Help?"; "REMEMBER:"; "REMEMBER:"; } local title = script.Parent.Title local cont = script.Parent.Content local content = { --The content "Use the 911 callbox to get help!"; "Stick to the speed limit! People are trying not to get hurt!"; "Trespassing is a crime! Trespassing on other's properties will get you arrested!"; } workspace.CMessages.Changed:connect(function(emergency) if emergency then title.Text = "Park Emergency" cont.Text = game.Workspace.CMessages.EMessage.Value else for i,r in ipairs(titles) do title.Text = titles[i] cont.Text = content[i] wait(nextMsg) end end end)