Ello, what’s wrong with this script? I don’t really have a goal for this script I’m trying to learn if not statements to make like on and off buttons.
Code:
They changed the behaviour so that luau autocomplete flags using not
and also ==
in the same condition as a warn, so just use
if Button.Text ~= "Text1" then
--Do
end
--Alternatively using ternary to shorten
Button.Text = Button.Text ~= "Text1" and "Text1" or "Text2"
It’s not an error, just a warning that it is not the best way to do it. The post above this one explains the correct way to do it
I’m trying to learn buttons and how to turn them off and on. Could I have a example if you press a button it turns on and if you press it again it turns off. Using a if not statement?
Try this
local button = script.Parent
button.MouseButton1Click:Connect(function()
if button.Text == "Text1" then
button.Text = "Text2"
else
button.Text = "Text1"
end
end)
local Button = script.Parent
Button.MouseButton1Click:Connect(function()
if Button.Text ~= "Text1" then
Button.Text = "Text1"
else
Button.Text = "Text2"
end
end)
No. I want a on and off button. So like can I have an example of an on and off button using a else if statement. So like if you press something shadows will enable and if u press the SAME button again it turns off shadows.
Could I have an example on how you would make a on and off button that turns on and off shadows while pressing the SAME button.
Here, put this in the button you want to remove the shadows
local button = script.Parent
if game.Lighting.GlobalShadows == true then --Check if the shadows are enabled/disabled on player respawn
button.Text = "Shadows : TRUE"
else
button.Text = "Shadows : FALSE"
end
button.MouseButton1Click:Connect(function()
if game.Lighting.GlobalShadows == true then
game.Lighting.GlobalShadows = false
button.Text = "Shadows : FALSE"
else
game.Lighting.GlobalShadows = true
button.Text = "Shadows : TRUE"
end
end)
so umm adding a not in a if with a == warns you that instead of that just do “~=” so
if Button.Text ~= "Text1" then
Well I don’t want to remove shadows I’m getting an idea on how on and off buttons work and how you would script them.
Can you try to be precise on what you’re trying to do?
Well I’m trying to learn how to script on and off buttons for fun. I’m trying to see how people would do that. Where I kind of understand how to make them now.
Nice!
I can give you this template, but I’m not sure if it’ll be useful lol
local button = script.Parent
if YourStatmentsHere.Enabled == true then --Check if the statement is enabled/disabled on player respawn
button.Text = "Enabled"
else
button.Text = "False"
end
button.MouseButton1Click:Connect(function()
if statement.Enabled == true then
statement.Enabled = false --Function (turn off)
button.Text = "False"
else
statement.Enabled = true --Function(turn on)
button.Text = "True"
end
end)
I got a question. Is this just based on how the person wants to do it??
Since I realized that sometimes people do it where they like do if it’s enabled it will be true. Example is down below.
if ____ == true then
button.Text = "Enabled'
else
button.Text = "False"
BUT sometimes people do the opposite like if it’s true they make it false.
if ___ == true then
__ = false
the first one
if ____ == true then
button.Text = "Enabled'
else
button.Text = "False"
Will check the settings on player respawn
local Enabled = false
local function OnClick()
Enabled = not Enabled
if Enabled then
--Do code.
else
--Do other code.
end
end
Making a toggle button is relatively simple.