i have made or tried chat function but i did while true do and i put wait(9) when the wait done the function will run again twice
coroutine.wrap(function()
if roundType == "Banana" then
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i].Chatted:Connect(function(msg)
if msg == "banana" then
print("Im an epic banana")
end
end)
end
end
end
end)()
like when the first function is functioning it will do
im an epic banana
and when the wait done
it will do im an epic banana (2x)
coroutine.wrap(function()
if roundType == "Banana" then
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i].Chatted:Connect(function(msg)
if msg == "banana" then
print("Im an epic banana")
end
end)
end
end
end
end)()
while true do
wait()
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i].Chatted:Connect(function(msg)
if msg == "banana" then
print("Im an epic banana")
wait(9)
if thing == thing then
break
end
end
end)
end
end
end
I’m so confused, what are you trying to accomplish?
Also don’t make connections in a while loop like that it will run the code passed to :Connect every time it’s fired as many times as the while loop created a connection. (sorry for bad explanation, basically if the while loop connects .Chatted 10 times, every time the player chats the function will run 10 times)
local timer = game.ReplicatedStorage.Value.Timer
local maps = game.ReplicatedStorage.Maps:GetChildren()
while true do
for i = 1,10 do
timer.Value = "".. 10-i
wait(1)
end
local rand = math.random(1,#maps)
local map = maps[rand]:Clone()
map.Parent = game.Workspace.Map
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
local teleporter = math.random(1,#map.Spawn:GetChildren())
players[i].Character:MoveTo(map.Spawn:GetChildren()[teleporter].Position)
players[i].Character.Parent = workspace.Ingame
end
end
local roundLength = 50
local roundType = ""
if map:FindFirstChild("Banana") then
roundType = "Banana"
roundLength = roundLength + 30
elseif map:FindFirstChild("Mango") then
roundType = "Mango"
roundLength = roundLength + 10
end
coroutine.wrap(function()
if roundType == "Banana" then
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i].Chatted:Connect(function(msg)
if msg == "banana" then
print("Im an epic banana")
end
end)
end
end
end
end)()
coroutine.wrap(function()
if roundType == "Mango" then
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i].Chatted:Connect(function(msg)
if msg == "mango" then
print("Im an epic mango")
end
end)
end
end
end
end)()
repeat
roundLength -= 1
timer.Value = ""..roundLength
wait(1)
until
roundLength == 0 and roundType == "Banana" or
#workspace.Ingame:GetChildren() == 0 and roundType == "Banana" or -- Banana
----------------------------------------------------------------------------------------------
roundLength == 0 and roundType == "Mango" or
#workspace.Ingame:GetChildren() == 0 and roundType == "Mango" -- Mango
wait()
roundType = ""
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
players[i]:LoadCharacter()
map:Destroy()
end
end
end
If you want something to happen when any player chats you do
local function onChatted (message)
print(message)
end
for _,player in ipairs(game.Players:GetPlayer())do
player.Chatted:Connect(onChatted)
end
game.Players.PlayerAdded:Connect(onChatted)
You still didn’t tell me what you are trying to do, again I wouldn’t make connections in a while loop in the full code you posted.
local connections = {}
coroutine.wrap(function()
if roundType == "Banana" then
local players = game.Players:GetChildren()
for i = 1,#players do
if players[i].Character ~= nil then
connection[player] = players[i].Chatted:Connect(function(msg)
if msg == "banana" then
print("Im an epic banana")
end
end)
end
end
end
end)()
------
-- at the end of your while loop
for _,con in pairs(connections)do
con:Disconnect()
end
my guy I don’t know what you are talking about, I don’t think you understand the problem here.