Hey there. First of all, I'm a newbie in LUA (I don't care if you call me noob, because I actually am) so please if you answer do it in stupid lenguage for stupid newbies. Thanks!
Anyway, I'm developing a disaster survival game and I'm adding a tip script. Everything is cool, but I found out a glitch that I don't know how to fix. The script is a localscript called "SystemMessageTips" inside StarterCharacterScripts, that has inside a bool value "TipsEnabled" that starts in true. This is the script:
local function SendTip(msg) game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = msg; Color = Color3.fromRGB(250, 250, 250); Font = Enum.Font.Arial; TextSize = 12 }) end local tips = { "You can disable these annoying tips on settings.", "You can use ROBUX to buy power-ups!", "Survive disasters to get coins!", "Renember to like and favourite this game if you enjoyed!", "This game still on testing and it may contain glitches. See the description to report glitches.", "We'd love to hear about you! Have a sugguestion or just wanted to tell anything? Look at the description!", "You can espectate your friend while you're in the lobby!" } while script.TipsEnabled.Value == true do wait(math.random(3, 5)) --This duration will be changed, it's so fast just for debug. SendTip("Tip: ".. tips[math.random(1, #tips)]) end
The idea is that when TipsEnabled is True, tips will be generated, but when it's false, they won't. And everything was cool, TipsEnabled was true and tips were being generated. And when TipsEnabled was false, tips weren't being generated. All fine, until I found that when I enabled back TipsEnabled, tips weren't being generated. I think that the problem is that when "while script.TipsEnabled.Value == true do" the script ends. How may I "execute again" the script when it's true back? Or is there another solution?
Thanks for your time, Aimarekin.
Instead of a while loop try using a if then statement,
local function SendTip(msg)
game.StarterGui:SetCore("ChatMakeSystemMessage", { Text = msg; Color = Color3.fromRGB(250, 250, 250); Font = Enum.Font.Arial; TextSize = 12 })
end
local tips = { "You can disable these annoying tips on settings.", "You can use ROBUX to buy power-ups!", "Survive disasters to get coins!", "Renember to like and favourite this game if you enjoyed!", "This game still on testing and it may contain glitches. See the description to report glitches.", "We'd love to hear about you! Have a sugguestion or just wanted to tell anything? Look at the description!", "You can espectate your friend while you're in the lobby!" }
If script.TipsEnabled.Value == true then wait(math.random(3, 5)) --This duration will be changed, it's so fast just for debug. SendTip("Tip: ".. tips[math.random(1, #tips)]) end