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

Help with a Voice Command bug?

Asked by
Nidoxs 190
10 years ago

So I have a script and when the "Admin" speaks a certain Phrase it executes a function but when I speak (I'm an Admin.) It executes the function to ANYTHING that I say and not the desired phrase/command. Here is the script. Please help! Much apreciated! :)

01Admins = {"doctorbenny2011"}
02function onChatted(msg)
03if string.find(string.lower(msg), string.lower("Vortex")) and
04    string.find(string.lower(msg), string.lower("Open!")) then
05on()
06 
07if string.find(string.lower(msg), string.lower("Vortex")) and
08    string.find(string.lower(msg), string.lower("Close!")) then 
09    off()
10    end
11end
12end
13 
14game.Players.PlayerAdded:connect(function (guy)
15    for i,v in pairs(Admins) do
View all 23 lines...

1 answer

Log in to vote
1
Answered by 10 years ago

It will be alot easier to make a command a new way using a function called onChatted(message, player)

01Admins = {"doctorbenny2011"}
02 
03function onChatted(message, player)
04    if string.lower(message:sub(1,7)) == "Vortex " then
05        if Admins[player.Name] then
06            if message:sub(8) == "Open!" or "open!" then
07                on()
08            elseif message:sub(8) == "Close!" or "close!" then
09                off()
10            end
11        end
12    end
13end
14game.Players.PlayerAdded:connect(function(player)
15    player.Chatted:connect(function(message) onChatted(message, player) end)
16end)

game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(message) onChatted(message, player) end) end) Calls the function every time someone talks when they are added to the server and sends the function the arguments message, player. if message.lower(:sub(1,7)) == "Vortex " then this checks the first 7 letters of the word for Vortex with a space afterwards. if Admins[player.Name] then This finds the table Admins and searches for the players name from the game.Players.PlayerAdded event and checks if it matches any of the names in the list. if message:sub(8) == "Open!" or "open!" then This then checks the letters after 8 to see if they match Open! or open! and calls the function on() elseif message:sub(8) == "Close!" or "close!" then This does the same as Open! but calls the function off()

0
:sub the colon is red. Nidoxs 190 — 10y
0
it shouldnt be, i use this layout for voice commands all the time, its never failed me so far. Rythian2277 65 — 10y
0
quick fix. Rythian2277 65 — 10y
Ad

Answer this question