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

Channel is a nil value?

Hello, I'm currently editing an radio and I have 1 problem with the UpdateScript:

wait(1)
MainGUI = script.Parent
GUI = MainGUI.Frame
Tool = MainGUI.Tool


function Update()
	connectedchannel = script.Parent.Frame.Network.CNetwork.Value
	Channel = game.Workspace:FindFirstChild(connectedchannel)
	GUI.Line1.Text = Channel.Line1.Value
	GUI.Line2.Text = Channel.Line2.Value
	GUI.Line3.Text = Channel.Line3.Value
	GUI.Line4.Text = Channel.Line4.Value
	GUI.Line5.Text = Channel.Line5.Value
	GUI.Line6.Text = Channel.Line6.Value
	GUI.Line7.Text = Channel.Line7.Value
	Tool.Value.Handle.Alert.Volume = 0.4
	Tool.Value.Handle.Alert.Run.Value = true
end


Channel.Line7.Changed:connect(Update)
wait(0.2)
Update()

When I equip the radio it says the following: Players.Player.PlayerGui.OfficerRadio.UpdateScript:22: attempt to index global 'Channel' (a nil value) Stack Begin Script 'Players.Player.PlayerGui.OfficerRadio.UpdateScript', Line 22 Stack End

My buddy and I can't solve the problems.

2 comments

0

Bump

0

This isn't going to bump. Also, I recommend where it says, Network.CNetwork.Value, to leave out the .Value part.

2 answers

✓ Accepted answer

Channel is not defined until the function Update() runs. The function only runs in an event that can not be triggered since Channel does not exist yet according to your script.

wait(1)
MainGUI = script.Parent
GUI = MainGUI.Frame
Tool = MainGUI.Tool

local connectedchannel = '';
Channel = game.Workspace:findFirstChild(connectedchannel);


function Update()
    connectedchannel = script.Parent.Frame.Network.CNetwork.Value
    GUI.Line1.Text = Channel.Line1.Value
    GUI.Line2.Text = Channel.Line2.Value
    GUI.Line3.Text = Channel.Line3.Value
    GUI.Line4.Text = Channel.Line4.Value
    GUI.Line5.Text = Channel.Line5.Value
    GUI.Line6.Text = Channel.Line6.Value
    GUI.Line7.Text = Channel.Line7.Value
    Tool.Value.Handle.Alert.Volume = 0.4
    Tool.Value.Handle.Alert.Run.Value = true
end


Channel.Line7.Changed:connect(Update)
wait(0.2)
Update()

10 comments

0

So, How can I solve it?

0

Define Channel outside of the function

0

This guys right. He's saying you should change line 9 and put it at the top of the script. Just in case you didn't catch that already xD

0

Gg, It doesnt work as Connectedchannel is still in the function.

0

updated my post. just define a variable that stores the connected channel for it to search for.

0

It still doesnt work :/ Still the same message.

0

had an error. try it now

0

I tryed that too before you edited it e.e 20:04:11.344 - Players.Player.PlayerGui.OfficerRadio.UpdateScript:24: attempt to index global 'Channel' (a nil value)

0

It's because channel is nil at the top. You should have a default channel you can set it to. So at the top for: local connectedchannel = 'put a default channel here'

0

Well, It only works for the Default Channel :/ If I switch to an other channel it doesnt work there.

My friend did it on a different way, Posting here, Maybe we could help some people :D

wait(1)
MainGUI = script.Parent
GUI = MainGUI.Frame
Tool = MainGUI.Tool

Channel1Model = game.Workspace:FindFirstChild("MPD-Radio")
mdotModel = game.Workspace:FindFirstChild("MDOT-Radio")
mdpsModel = game.Workspace:FindFirstChild("MDPS-Radio")

function updateChannel1()
 connectedchannel = script.Parent.Frame.Network.CNetwork.Value
 Channel = game.Workspace:FindFirstChild(connectedchannel)

 if Channel == Channel1Model then
  GUI.Line1.Text = Channel.Line1.Value
  GUI.Line2.Text = Channel.Line2.Value
  GUI.Line3.Text = Channel.Line3.Value
  GUI.Line4.Text = Channel.Line4.Value
  GUI.Line5.Text = Channel.Line5.Value
  GUI.Line6.Text = Channel.Line6.Value
  GUI.Line7.Text = Channel.Line7.Value
  Tool.Value.Handle.Alert.Volume = 0.4
  Tool.Value.Handle.Alert.Run.Value = true
 end
end

function updateChannel2()
 connectedchannel = script.Parent.Frame.Network.CNetwork.Value
 Channel = game.Workspace:FindFirstChild(connectedchannel)

 if Channel == Channel2Model then
  GUI.Line1.Text = Channel.Line1.Value
  GUI.Line2.Text = Channel.Line2.Value
  GUI.Line3.Text = Channel.Line3.Value
  GUI.Line4.Text = Channel.Line4.Value
  GUI.Line5.Text = Channel.Line5.Value
  GUI.Line6.Text = Channel.Line6.Value
  GUI.Line7.Text = Channel.Line7.Value
  Tool.Value.Handle.Alert.Volume = 0.4
  Tool.Value.Handle.Alert.Run.Value = true
 end
end

function updateChannel3()
 connectedchannel = script.Parent.Frame.Network.CNetwork.Value
 Channel = game.Workspace:FindFirstChild(connectedchannel)

 if Channel == Channel3Model then
  GUI.Line1.Text = Channel.Line1.Value
  GUI.Line2.Text = Channel.Line2.Value
  GUI.Line3.Text = Channel.Line3.Value
  GUI.Line4.Text = Channel.Line4.Value
  GUI.Line5.Text = Channel.Line5.Value
  GUI.Line6.Text = Channel.Line6.Value
  GUI.Line7.Text = Channel.Line7.Value
  Tool.Value.Handle.Alert.Volume = 0.4
  Tool.Value.Handle.Alert.Run.Value = true
 end
end


Channel1Model.Line7.Changed:connect(updateChannel1)
Channel2Model.Line7.Changed:connect(updateChannel2)
Channel3Model.Line7.Changed:connect(updateChannel3)

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