Hi! I’m making a nextbot game, where when you say a certain word, a certain nextbot spawns. I have an issue where if a player says anything, both nextbots spawn at once and I don’t know why. Here are both codes:
Cop Script
local nextbots = game:GetService("ServerStorage"):WaitForChild("Nextbots")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg == "cop" or "Cop" or "Police" or "Popo" or "911" or "Officer" or "Cadet" or "Sergeant" then
local cop = nextbots:WaitForChild("Cop"):Clone()
cop.Parent = workspace
else end
end)
end)
Rock Script
local nextbots = game:GetService("ServerStorage"):WaitForChild("Nextbots")
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
if msg == "Rock" or "Dwayne Johnson" or "The Rock" or "Dwayned the Rock Johnson" then
local rock = nextbots:WaitForChild("Rock"):Clone()
rock.Parent = workspace
else end
end)
end)
I guess he should use a table then…
Something like this:
Even though I haven’t used tables in a while, so I might have forgotten.
local serverStorage = game:GetService("ServerStorage")
local nextbots = serverStorage.Nextbots
local list = {"cop", "Cop", "Police", "Popo", "911", "Officer", "Cadet", "Sergeant"}
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if message == list then
nextbots.Cop:Clone().Parent = workspace
else
print("Couldn't find a word within the table list.")
end
end)
end)
If “if message == list then” is incorrect, then somebody can then correct me.
You need a For loop to index the table if you use that method:
local nextbots = game:GetService("ServerStorage"):WaitForChild("Nextbots")
copTable = { "cop","police","popo","911","officer","cadet","sergeant" }
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
msg = string.lower(msg) --make the message lowercase
for i=1,#copTable do
if string.match(copTable[i],msg) then
local cop = nextbots:WaitForChild("Cop"):Clone()
cop.Parent = workspace
break
end
end
end)
end)
local nextbots = game:GetService("ServerStorage"):WaitForChild("Nextbots")
rockTable = { "rock","dwayne johnson","the rock","dwayned the rock johnson" }
game.Players.PlayerAdded:Connect(function(plr)
plr.Chatted:Connect(function(msg)
msg = string.lower(msg) --make the message lowercase
for i=1,#rockTable do
if string.match(rockTable[i],msg) then
local cop = nextbots:WaitForChild("Cop"):Clone()
cop.Parent = workspace
break
end
end
end)
end)
local list = {"cop", "Cop", "Police", "Popo", "911", "Officer", "Cadet", "Sergeant"}
game.Players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
if table.find(list, message) then
nextbots.Cop:Clone().Parent = workspace
else
print("Couldn't find a word within the list tabel.")
end
end)
end)