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

What did I do wrong while scripting a radio? I need help!

So I'm making a radio system with "radio stations" in folders. I've made it to detect that a radio station is in game. The code is

local Frequency = script.Parent.Parent.Frequency
local Station1 = game.Workspace.RadioStations:FindFirstChild("Test1")
local Station2 = game.Workspace.RadioStations:FindFirstChild("Test2")
function onClicked()
if Frequency.Value == 1 then 
if Station1 then 
script.Parent.Parent.MessageScreen.SurfaceGui.SuccessMessage.Visible = true
elseif Frequency.Value == 2 then
elseif Station2 then 
script.Parent.Parent.MessageScreen.SurfaceGui.SuccessMessage.Visible = true


end
end
end 
script.Parent.ClickDetector.MouseClick:connect(onClicked)

The SurfaceGUI for Frequency 1 works, but if I set frequency to 2 and press the button, it doesn't show up the message. Please help me.

2 answers

✓ Accepted answer

So the code should be

local Frequency = script.Parent.Parent.Frequency
local Station1 = game.Workspace.RadioStations:FindFirstChild("Test1")
local Station2 = game.Workspace.RadioStations:FindFirstChild("Test2")
function onClicked()
	if Frequency.Value == 1 and Station1 then
		script.Parent.Parent.MessageScreen.SurfaceGui.SuccessMessage.Visible = true
	elseif Frequency.Value == 2 and Station2 then
		script.Parent.Parent.MessageScreen.SurfaceGui.SuccessMessage.Visible = true	 
	end
end
16	script.Parent.ClickDetector.MouseClick:connect(onClicked)

The Prroblem

so you're using elseif to times in a row, you should use an and gate. Because elseif means if the previous elseif is false then do that one or skip it. so if you use an and gate it would work.

Tip Indent your code

1 comment

0

Thank you! You've fixed my script!

Line 9: You should be using if instead of elseif.

You could also save yourself a couple lines by using and:

if (frequency.Value == 1) and (Station1) then
	-- blah blah
elseif (frequency.Value == 2) and (Station2) then
	-- blah blah 2
end

5 comments

0

i already answered

0

i already answered

0

i already answered

0

ok theres this glitch going on

0

Beat me to it.

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