chats = {"how do i play this game","nub","help plz","im gonna spawn in a zombie"}
game.Players.PlayerAdded:Connect(function(player)
wait(3)
game:GetService("Chat"):Chat(script.Parent.Head, "hi "..player.Name, Enum.ChatColor.Green)
end)
while true do
wait(6)
game:GetService("Chat"):Chat(script.Parent.Head, chats[math.random(1, #chats)], Enum.ChatColor.Green)
end
dont directly put the chats math random in the chat event, instead put it in a variable, and after chatting, just check if the message is equal to the one you want
How would that work because i dont really know how to script that much
while true do
wait(6)
local message = chats[math.random(1, #chats)]
game:GetService("Chat"):Chat(script.Parent.Head, message, Enum.ChatColor.Green)
if message == "im gonna spawn in a zombie" then
-- spawn a zombie
end
end
im gonna try it out, if it works i will make this the solution
The code listed by ProPlayerCookie
could work but it’s not too flexible, here is a better version:
local keywords = {"spawn","zombie","summon"} -- Basically the words that would be said by the AI when he would spawn the zombies.
-- The rest of your code.
for _,keyword in keywords do
if string.find(message:lower(),keyword:lower() then
-- Summon a zombie.
end
end
Now any text that has the words zombie or spawn or summon would spawn a zombie, you could add more rules to it if your AI may randomly say things like: “Oh no! Watch out for that zombie!”
To fix this you can just add more specific key words like: “spawn zombie”, “spawn in a zombie” etc.
Or alternatively justt label some of your words like so:
chats = {{Message = "how do i play this game",SpawnsZombie = false},{Message = "im gonna spawn in a zombie",SpawnsZombie = true}}
game:GetService("Chat"):Chat(script.Parent.Head, chats[math.random(1, #chats)].Message, Enum.ChatColor.Green)
if message.SpawnsZombie then
-- spawn zombie
end
idk how to put in what order im confused
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.