It says it's a nil value but it's not? [SOLVED]
Asked by
8 years ago Edited 8 years ago
So, i am making a voice chat script and testing out the ban feature.
It is supposed to check if the speaker is an admin, so only admins can use the ban feature.
It just returns: 77, attempt to index local 'speaker' (a nil value)
I tried copying and pasting from wiki but the error still repeats!
Anyways, enough of this talking. Here is the code:
03 | local admins = { ARTEK 22 } |
06 | local model = Instance.new( "Model" ) |
07 | model.Name = "Chat Voice sounds" |
08 | model.Parent = workspace |
10 | local trains = Instance.new( "Sound" ) |
15 | local no = Instance.new( "Sound" ) |
20 | local only = Instance.new( "Sound" ) |
25 | local scarce = Instance.new( "Sound" ) |
31 | for i,v in pairs (game.Players:GetChildren()) do |
33 | local sgui = Instance.new( "ScreenGui" ) |
34 | sgui.Parent = v.PlayerGui |
36 | local frame = Instance.new( "Frame" ) |
38 | frame.BackgroundColor 3 = BrickColor.Black().Color |
39 | frame.Position = UDim 2. new( 0 , 200 , 0 , 25 ) |
40 | frame.Size = UDim 2. new( 0 , 300 , 0 , 300 ) |
44 | local title = Instance.new( "TextLabel" ) |
45 | title.BackgroundTransparency = 1 |
46 | title.TextStrokeTransparency = 0 |
48 | title.TextScaled = true |
49 | title.TextColor 3 = BrickColor.White().Color |
50 | title.Text = "Chat Voice" |
51 | title.Size = UDim 2. new( 0 , 300 , 0 , 50 ) |
53 | local info = Instance.new( "TextLabel" ) |
54 | info.BackgroundTransparency = 1 |
55 | info.TextStrokeTransparency = 0 |
57 | info.TextScaled = true |
58 | info.Position = UDim 2. new( 0 , 000 , 0 , 75 ) |
59 | info.TextColor 3 = BrickColor.White().Color |
60 | info.Text = 'Type in "voicechat/commands" to see the commands!' |
61 | info.Size = UDim 2. new( 0 , 300 , 0 , 50 ) |
63 | local textButton = Instance.new( "TextButton" ) |
64 | textButton.BackgroundColor 3 = BrickColor.Red().Color |
65 | textButton.TextColor 3 = BrickColor.White().Color |
66 | textButton.Parent = frame |
67 | textButton.Position = UDim 2. new( 0 , 100 , 0 , 200 ) |
68 | textButton.Size = UDim 2. new( 0 , 100 , 0 , 50 ) |
69 | textButton.TextScaled = true |
70 | textButton.Text = "Got it!" |
72 | textButton.MouseButton 1 Down:Connect( function () |
76 | v.Chatted:connect( function (msg, speaker) |
78 | if string.lower(msg) = = "i like trains" then |
80 | elseif string.lower(msg) = = "no" then |
82 | elseif string.lower(msg) = = "i am the one and only" then |
84 | elseif string.lower(msg) = = "hey whats up guys its scarce here" then |
86 | elseif string.lower(msg) = = "voicechat/commands" then |
87 | local m = Instance.new( "Message" ) |
89 | m.Text = "Sorry, 'voicechat/commands' is under construction." |
92 | elseif string.lower(string.sub(msg, 1 , 14 )) = = "voicechat/ban/" and tableContains(admins, speaker.Name) then |
93 | local number = #speakbanned + 1 |
and here is what part i am having trouble with.
1 | elseif string.lower(string.sub(msg, 1 , 14 )) = = "voicechat/ban/" and tableContains(admins, speaker.Name) then |
2 | local number = #speakbanned + 1 |