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

Channel is a nil value?

Asked by
DeepDev 101
8 years ago

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.

0
Bump DeepDev 101 — 8y
0
This isn't going to bump. Also, I recommend where it says, Network.CNetwork.Value, to leave out the .Value part. Async_io 908 — 8y

2 answers

Log in to vote
1
Answered by 8 years ago

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()

0
So, How can I solve it? DeepDev 101 — 8y
0
Define Channel outside of the function Legoman654 100 — 8y
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 User#11440 120 — 8y
0
Gg, It doesnt work as Connectedchannel is still in the function. DeepDev 101 — 8y
View all comments (6 more)
0
updated my post. just define a variable that stores the connected channel for it to search for. Legoman654 100 — 8y
0
It still doesnt work :/ Still the same message. DeepDev 101 — 8y
0
had an error. try it now Legoman654 100 — 8y
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) DeepDev 101 — 8y
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' Legoman654 100 — 8y
0
Well, It only works for the Default Channel :/ If I switch to an other channel it doesnt work there. DeepDev 101 — 8y
Ad
Log in to vote
0
Answered by
DeepDev 101
8 years ago

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)

Answer this question