i have this night vision script and i want it to indicate whether it is on or not by changing the playergui to show that it is on
it should look like this off
and then it should look like this on
how would i make this work?
i have this night vision script and i want it to indicate whether it is on or not by changing the playergui to show that it is on
it should look like this off
and then it should look like this on
how would i make this work?
Would you mind posting some of your script so we can get a better understanding of how it’s set-up in your game and we can better help you.
Thanks, Opex.
This is pretty simple and you should be utilising BoolValues
to accomplish this. Simply add a LocalScript
and a BoolValue
into the button and try the following code. Also name the BoolValue
something like Enabled
.
local button = script.Parent
local enabled = button.Enabled -- or whatever you named the value
button.MouseButton1Click:Connect(function()
if (enabled.Value == false) then
button.Text = "Night Vision: On"
enabled.Value = true
elseif (enabled.Value == true) then
button.Text = "Night Vision: Off"
enabled.Value = false
end
end)
All you’re doing in this code is adding an event to check when the button is clicked. When it is clicked, we’re checking if the Enabled BoolValue is true or false. If it’s false, it means that night vision is off, so we turn it on and vice versa. Also note how we’re changing the value of the BoolValue as we use this to check if Night Vision is on or off.
Hope my explanation made some sense.
local textbutton = script.Parent
local toggle = false
textbutton.MouseButton1Click:Connect(function()
toggle = not toggle
textbutton.Text = if toggle then "Yes!" else "No!"
end)
Relatively simple.