Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

local oncd = script.Parent.On.ClickDetector
local offcd = script.Parent.Off.ClickDetector
local screen = script.Parent.Screen
local ison = false

if oncd.MouseClick then
	if ison == false then
		screen.Color = Color3.new(190, 104, 98)
		script.Sound:Play()
		ison = true
	end
end
if offcd.MouseClick then
	if ison == true then
		screen.Color = Color3.new(0, 0, 0)
		script.Sound:Pause()
		ison = false
	end
end

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

✓ Accepted answer

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

local oncd = script.Parent.On.ClickDetector
local offcd = script.Parent.Off.ClickDetector
local screen = script.Parent.Screen
local ison = false

oncd.MouseClick:Connect(function()
    if ison == false then
        screen.Color = Color3.new(190, 104, 98)
        script.Sound:Play()
        ison = true
    end
end)

offcd.MouseClick:Connect(function()
    if ison == true then
        screen.Color = Color3.new(0, 0, 0)
        script.Sound:Pause()
        ison = false
    end
end)

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

local on = script.Parent.On
local off = script.Parent.Off
local screen = script.Parent.Screen
local ison = false

on.MouseButton1Click:Connect(function()
    if ison == false then
        screen.Color = Color3.new(190, 104, 98)
        script.Sound:Play()
        ison = true
    end
end)

off.MouseButton1Click:Connect(function()
    if ison == true then
        screen.Color = Color3.new(0, 0, 0)
        script.Sound:Pause()
        ison = false
    end
end)

2 comments

0

yes did work :0

0

Happy to help

This discussion is preserved as it was. New answers, comments, and votes are closed.