Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why isn't the "function" doing anything (Making the screen terracota, playing the sound, etc. etc.)?

Asked by 5 years ago
01local oncd = script.Parent.On.ClickDetector
02local offcd = script.Parent.Off.ClickDetector
03local screen = script.Parent.Screen
04local ison = false
05 
06if oncd.MouseClick then
07    if ison == false then
08        screen.Color = Color3.new(190, 104, 98)
09        script.Sound:Play()
10        ison = true
11    end
12end
13if offcd.MouseClick then
14    if ison == true then
15        screen.Color = Color3.new(0, 0, 0)
16        script.Sound:Pause()
17        ison = false
18    end
19end

The script is doing absolutely nothing, or it is but it's just super fast to the eye. But I can't point out exactly why it is, it looks perfectly good to me. Especially because there aren't errors.

help me.

thanks for reading and or help,

Narwhal

1 answer

Log in to vote
0
Answered by 5 years ago

This is probably happening because the script doesn't loop, try using functions, edited code:

01local oncd = script.Parent.On.ClickDetector
02local offcd = script.Parent.Off.ClickDetector
03local screen = script.Parent.Screen
04local ison = false
05 
06oncd.MouseClick:Connect(function()
07    if ison == false then
08        screen.Color = Color3.new(190, 104, 98)
09        script.Sound:Play()
10        ison = true
11    end
12end)
13 
14offcd.MouseClick:Connect(function()
15    if ison == true then
16        screen.Color = Color3.new(0, 0, 0)
17        script.Sound:Pause()
18        ison = false
19    end
20end)

Also, if this is a GUI then make sure On and Off are text buttons and use the following code:

01local on = script.Parent.On
02local off = script.Parent.Off
03local screen = script.Parent.Screen
04local ison = false
05 
06on.MouseButton1Click:Connect(function()
07    if ison == false then
08        screen.Color = Color3.new(190, 104, 98)
09        script.Sound:Play()
10        ison = true
11    end
12end)
13 
14off.MouseButton1Click:Connect(function()
15    if ison == true then
16        screen.Color = Color3.new(0, 0, 0)
17        script.Sound:Pause()
18        ison = false
19    end
20end)
0
yes did work :0 NarwhalAndMe 141 — 5y
0
Happy to help Lord_WitherAlt 206 — 5y
Ad

Answer this question