What do you want to achieve?
I want to achieve a TextLabel that appears that says “Power = ON”, it disappears after 3 seconds. I then want it to say “Power = OFF” if it is pressed again.
What is the issue?
I cannot achieve it yet.
What solutions have you tried so far?
I have looked around on the developer hub, and on the forums however I haven’t found anything.
Make a BoolValue in the PowerButton.
And Rename it to BoolValue
Use .MouseButton1Click event with the PowerButton.
You should put the code in a LocalScript within PowerButton.
When it is clicked, set the BoolValue.Value in PowerButton to “not” it’s value. Your code will look like this…
script.Parent.MouseButton1Click:Connect(function()
script.Parent.BoolValue.Value = not script.Parent.BoolValue.Value -- Sets to NOT it's value. Basically the opposite.
end)
Next we make “if” statement to check IF the value is true or false.
script.Parent.MouseButton1Click:Connect(function()
script.Parent.BoolValue.Value = not script.Parent.BoolValue.Value -- Sets to NOT it's value. Basically the opposite.
if script.Parent.Parent.BoolValue.Value == false then
else
end
end)
Now, click on PowerMode, go to its properties and disable the property, “Visible”.
After that, we have to make the PowerMode visible for a short time and set its text too.
Next we shall add the code that will do what I said above.
We will make the PowerMode visible for a short amount of time and also set the text.
script.Parent.MouseButton1Click:Connect(function()
script.Parent.BoolValue.Value = not script.Parent.BoolValue.Value -- Sets to NOT it's value. Basically the opposite.
if script.Parent.BoolValue.Value == false then
script.Parent.PowerMode.Text = "Power: OFF"
coroutine.wrap(function()
script.Parent.PowerMode.Visible = true
task.wait(3)
script.Parent.PowerMode.Visible = false
end)
else
script.Parent.PowerMode.Text = "Power: ON"
coroutine.wrap(function()
script.Parent.PowerMode.Visible = true
task.wait(3)
script.Parent.PowerMode.Visible = false
end)
end
end)
Let me know if any errors get arised. I will fix the code.