local Words = {
"yes",
"roblox",
"good",
"nice",
"hate",
"like",
"sleep",
"yo",
"chat",
"say"
}
for i,v in pairs(game.Players:GetPlayers()) do
local Word = Words[math.random(1, #Words)]
if #Words == 0 then break end
if v.Character then
v.Character.Head.Text.Text.Text = Word
game.ReplicatedStorage.Events.RemoteEvent:FireClient(v, "46T4GkhxgvMFHH9JL8KB", v.Character)
end
table.remove(Words, Word) -- invalid argument #2 to 'remove' (number expected, got string)
end
You need to give table.remove the index to remove, not the value. Since you want a random word you should keep track of what number you generated so you can use it to remove index.
local WordPos = math.random(#Words)
local Word = Words[WordPos]
-- ...
table.remove(Word, WordPos)
local Words = {
"yes",
"roblox",
"good",
"nice",
"hate",
"like",
"sleep",
"yo",
"chat",
"say"
}
for i,v in pairs(Words) do
local Word = math.random(#Words)
if #Words == 0 then break end
if v.Character then
v.Character.Head.Text.Text.Text = Word
game.ReplicatedStorage.Events.RemoteEvent:FireClient(v, "46T4GkhxgvMFHH9JL8KB", v.Character)
end
table.remove(Words, table.find(Words, Word))
end
print("Loop finished")
Replace local Word = Words[math.random(1, #Words)]
With local Word = math.random(1, #Words)
Also,
Replace v.Character.Head.Text.Text.Text = Word
With v.Character.Head.Text.Text.Text = Words[Word]
local Words = {
"yes",
"roblox",
"good",
"nice",
"hate",
"like",
"sleep",
"yo",
"chat",
"say"
}
for i,v in pairs(Words) do
local Word = math.random(#Words)
if #Words == 0 then break end
if v.Character then
v.Character.Head.Text.Text.Text = Word
game.ReplicatedStorage.Events.RemoteEvent:FireClient(v, "46T4GkhxgvMFHH9JL8KB", v.Character)
end
table.remove(Words, 1)
end
print("Loop finished")
local Remote = game:GetService("ReplicatedStorage"):WaitForChild("Events"):WaitForChild("RemoteEvent")
local Words = {
"yes",
"roblox",
"good",
"nice",
"hate",
"like",
"sleep",
"yo",
"chat",
"say"
}
for i, Player in pairs(game.Players:GetPlayers()) do
if #Words == 0 then break end
local WordIndex = math.random(1, #Words)
local Word = Words[WordIndex]
local Character = Player.Character
if Character then
local Head = Character:WaitForChild("Head")
if Head then
local Text1 = Head:WaitForChild("Text")
if Text1 then
local Text2 = Text1:WaitForChild("Text")
if Text2 then
Text2.Text = Word
end
end
end
Remote:FireClient(Player, "46T4GkhxgvMFHH9JL8KB", Character)
end
table.remove(Words, WordIndex)
end
The error where you put the “if #Words == 0 then break end” after the “local Word = Words[math.random(1, #Words)]” because the math.random(1, 0) would error before the script would break