Alright so, I’ve been trying to Script an On/Off type of System for my Game’s Settings, and even though I tried so many scripts and also looked it up online unsuccessfully, I’m unsure of what to do. As you can tell, I’m a really beginner Scripter, and I need your help on this.
This is the current state of the script that I hoped would work, but doesn’t:
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text = "OFF" == true then
script.Parent.Text = "ON"
end
if script.Parent.Text = "OFF" == false then
script.Parent.Text = "OFF"
end
end)
(That might be the current Script, but once I make it work, I’ll also add a TextColor3 change.) I’ve also tried using a Bool Value based on another related Post on the DevForum, but very unsuccessfully obviously. What do you think I should fix in that Script?
script.Parent.MouseButton1Click:Connect(function()
if script.Parent.Text == "OFF" then
script.Parent.Text = "ON"
elseif script.Parent.Text == "ON" then
script.Parent.Text = "OFF"
end
end)
A brief way:
script.Parent.MouseButton1Click:Connect(function()
script.Parent.Text = if script.Parent.Text == "OFF" then "ON" else "OFF"
end)
--Thanks for @EmbarTheHybrid for reminding this method
[You’d have to play with this one]
Here is the Ternary version:
local text = script.Parent
script.Parent.MouseButton1Click:Connect(function()
local NewText = text.Text == "ON" and "OFF" or "ON"
text.Text = NewText
end)
local text = script.Parent
script.Parent.MouseButton1Click:Connect(function()
local NewText = text.Text == "ON" and "OFF" or text.Text == "OFF" and "ON"
text.Text = NewText
end)