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

It says it's a nil value but it's not? [SOLVED]

Asked by
ARTEK22 135
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:

01-- get banned and admins
02local speakbanned = {}
03local admins = {ARTEK22}
04-- get sounds
05 
06local model = Instance.new("Model")
07model.Name = "Chat Voice sounds"
08model.Parent = workspace
09 
10local trains = Instance.new("Sound") -- make a new sound
11trains.Parent = model
12trains.SoundId = "rbxassetid://165384079" -- set id
13trains.Looped = false -- dont loop
14 
15local no = Instance.new("Sound")
View all 97 lines...

and here is what part i am having trouble with.

1elseif string.lower(string.sub(msg, 1, 14)) == "voicechat/ban/" and tableContains(admins, speaker.Name) then
2        local number = #speakbanned + 1
3        print(number)
4end

1 answer

Log in to vote
2
Answered by 8 years ago
Edited 8 years ago

The second variable of Chattedevent is the player that you are whispering to. It returns nil if you speak to the team or to everyone. Thats why you got an error.

To check if player is in the admins table just simply use this loop.

1local Player = game.Players.LocalPlayer
2local admins = {"Player1"}
3for i = 1,#admins do  
4             if player.Name == admins[i] then
5              -- Command--
6end
7end
0
I want it to have admin commands and nonadmin commands. As an admin i won't be able to use nonadmin commands. ARTEK22 135 — 8y
0
But you kinda gave me an idea. Instead of getting the player from the chatted event, im going to get it from the GetChildren one! ARTEK22 135 — 8y
0
Make sure to accept my answer. personal_ly 151 — 8y
Ad

Answer this question