Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Execute again script when a boolean is true back? [SOLVED]

Asked by
Aimarekin 345 Moderation Voter
6 years ago
Edited 6 years ago

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.

0
try using this above the while value true: script.showTips.Value.Changed:connect(function() (and ending with end),ofcourse) Karl_RBX 11 — 6y
1
Tried script.TipsEnabled.Value.Changed:connect(function() while script.TipsEnabled.Value == true do wait(math.random(3, 5)) SendTip("Tip: ".. tips[math.random(1, #tips)]) end end) but returned in the output Workspace.Aimarekin.SystemMessageTips:22: attempt to index field 'Value' (a boolean value) Aimarekin 345 — 6y
0
Try removing the 'Value'. Karl_RBX 11 — 6y
0
Thanks a lot, Karl! It worked! Could you please leave your answer in answers so that I can vote you? Thanks! PD: If I someday publish the game, I will thank you :D Aimarekin 345 — 6y

1 answer

Log in to vote
0
Answered by
nap516 87
6 years ago

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

0
Sorry for the error with the code, I'm new as of I just joined today. nap516 87 — 6y
0
lol doesnt care, if you look under your answer there should be a "Edit" button. Am I correct? PD: I'm new too! Aimarekin 345 — 6y
0
ty :) nap516 87 — 6y
Ad

Answer this question