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

Attempted to index nil with TextLabel fix?

Asked by 3 years ago

I am trying to make a police radio system and i am getting an nil error i am not able to fix I hope someonehere knows what the issue is.

Exact error: Players.loganmatt3.PlayerGui.RadioGui.ServerRadioScript:5: attempt to index nil with 'LineSix'

Script where error comes from:

01local RadioRemoteEvents = game.ReplicatedStorage.RadioRemoteEvents
02local RadioEvent = RadioRemoteEvents.RadioEvent
03 
04function DisplayMessage(Frame,Message)
05    Frame.LineSix.Text = Frame.LineFive.Text
06    Frame.LineFive.Text = Frame.LineFour.Text
07    Frame.LineFour.Text = Frame.LineThree.Text
08    Frame.LineThree.Text = Frame.LineTwo.Text
09    Frame.LineTwo.Text = Frame.LineOne.Text
10    Frame.LineOne.Text = Message
11end
12 
13function ConfigMessage(Player,Message,Channel)
14    local RadioGui = script.Parent
15    local Frame = RadioGui.RadioFrame:FindFirstChild(Channel)
View all 22 lines...

3 answers

Log in to vote
0
Answered by 3 years ago

There is no item with the name of the Channel variable inside RadioGui.RadioFrame.

The message isn't exactly intuitive I understand but in simpler terms it mean's you can't get the child LineSix of nil, something that doesn't exist.

Ensure that the 'Channel' argument getting sent to the client is the name of a direct child of RadioFrame.

Ad
Log in to vote
0
Answered by 3 years ago

Try replacing the .s with:FindFirstChild() the code should look like this.

01local RadioRemoteEvents = game.ReplicatedStorage.RadioRemoteEvents
02local RadioEvent = RadioRemoteEvents.RadioEvent
03 
04function DisplayMessage(Frame,Message)
05    Frame:FindFirstChild("LineSix").Text = Frame:FindFirstChild("LineFive").Text
06    Frame:FindFirstChild("LineFive").Text = Frame:FindFirstChild("LineFour").Text
07    Frame:FindFirstChild("LineFour").Text = Frame:FindFirstChild("LineThree").Text
08    Frame:FindFirstChild("LineThree").Text = Frame:FindFirstChild("LineTwo").Text
09    Frame:FindFirstChild("LineTwo").Text = Frame:FindFirstChild("LineOne").Text
10    Frame:FindFirstChild("LineOne").Text = Message
11end
12 
13function ConfigMessage(Player,Message,Channel)
14    local RadioGui = script.Parent
15    local Frame = RadioGui.RadioFrame:FindFirstChild(Channel)
View all 22 lines...

I really hope this helps! If this did help marking it as the answer would be good. If you have any other problems or this didn't work comment on this and we can test more things, lets get that radio workin'!

Log in to vote
0
Answered by
TGazza 1336 Moderation Voter
3 years ago

The structure of your script checks out, but you're not checking to see if things exist before calling/writing to them.

I've done a little example (ill paste the script(s) here at the end of this answer for reference)

The code I've written checks to see if our gui elements exist before printing. If they do exist, then continue as normal if they don't exist. For example, if we misspelled LineFour as LneFour or even linefour then the code will tell you that this doesn't exist in your display(s) and lets you know what display its missing.

Modified Code as follows:

ServerCode:

01local RadioRemoteEvents = game.ReplicatedStorage.RadioRemoteEvents
02local RadioEvent = RadioRemoteEvents.RadioEvent
03 
04function DisplayMessage(Frame,Message)
05 
06    local LineOne = Frame:FindFirstChild("LineOne")
07    local LineTwo = Frame:FindFirstChild("LineTwo")
08    local LineThree = Frame:FindFirstChild("LineThree")
09    local LineFour = Frame:FindFirstChild("LineFour")
10    local LineFive = Frame:FindFirstChild("LineFive")
11    local LineSix = Frame:FindFirstChild("LineSix")
12 
13    -- this embedded ambigus function simply returns the above values in a table to see if all exist
14    -- But this shouldn't be this complex but Roblox lua returns a table element that doesn't exist as void and not nil! **Pulls out hair!**
15    local CheckTble = (function()
View all 54 lines...

PlayerGui (Local Script) Code:

01local TextBox = script.Parent.TextBox
02local SubmitBtn = script.Parent["Submit Button"]
03local EventCaller_Storage = game:GetService("ReplicatedStorage")
04local EventCaller_FDR = EventCaller_Storage:WaitForChild("RadioRemoteEvents",10)
05local EventCaller = EventCaller_FDR:WaitForChild("RadioEvent",10)
06 
07SubmitBtn.MouseButton1Click:Connect(function()
08    local Message = TextBox.Text
09    EventCaller:FireServer(Message,"Channel One")
10end)

Hope this helps! :)

Answer this question