Hi devs, I need help with a script. This script should switch the textlabel text from off to on, and from on to off. This is the script I tried:
script.Parent.ClickDetector.MouseClick:Connect(function()
if script.Parent.SurfaceGui.TextLabel.Text == "Alarm: OFF" then
script.Parent.SurfaceGui.TextLabel.Text = "Alarm: ON"
print ("Alarm On")
else
script.Parent.SurfaceGui.TextLabel.Text = "Alarm: OFF"
print ("Alarm Off")
end
end)
This is the explorer screenshot:
(Nothing in the output)
Can you tell me what did I wrong? Thank you.
1 Like
Could you please put in a video of what happens when you play the game?
1 Like
Nothing happens but the same script worked with the GUI as you can see at the left
it’s probably something wrong with calling the function if there is no output
idk, I tried your script in my studio and it working
1 Like
For further debugging purposes, try this?
print("This should be running")
local Part = script.Parent
local TextLabel = Part.SurfaceGui.TextLabel
local function Clicked()
print("Event fired")
if TextLabel.Text == "Alarm: OFF" then
TextLabel.Text = "Alarm: ON"
print ("Alarm On")
else
TextLabel.Text = "Alarm: OFF"
print ("Alarm Off")
end
end)
Part.ClickDetector.MouseClick:Connect(Clicked)
Is not working… nothing in the output too. Maybe there is a bug in my place, I do not know.
I’m going to try the script in another place
Not working in another place too…
Are you sure you’re checking the correct Output side? You should be looking at the server’s Output (Or your Output tab)
Yes it was the correct tab, I tried in the other place my script and it is working.
lluckvy
(aaron)
May 17, 2021, 4:38pm
#11
local toggle = false -- Will determine if it's on/off
script.Parent.ClickDetector.MouseClick:Connect(function()
if not toggle then
script.Parent.SurfaceGui.TextLabel.Text = "Alarm: ON"
toggle = true
print ("Alarm On")
else
script.Parent.SurfaceGui.TextLabel.Text = "Alarm: OFF"
toggle = false
print ("Alarm Off")
end
end)
My script works, I think someone of my devs used a free model and it had a virus (I hope not) by the way thank you. I just tried my script in another place and, yes, it works.