Hello Developers! I’m trying to make a script run when all the players say “Done!” like if you say “Done!” a NPC will move, I will now answer these questions.
What do you want to achieve? Keep it simple and clear!
I’m trying to make a script run when all the players say “Done!” like if you say “Done!” a NPC will move,
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I tried asking someone but he said me is better creating a topic.
I want do a script run when all the players on the server say “Done!” if all says “Done!” a NPC will move.
This might help, you check the amount of players then if the player said Done! then compare the 2 values. It goes In a PlayerAdded function.
local Chatted = 0
local Players = 0
local function CheckMessage(msg)
local words = string.lower(msg)
for i,v in pairs(game.Players:GetChildren()) do
Player = Player + 1
end
if words == "Done!" then
Chatted = Chatted + 1
end
if Chatted == Players then
--stuff here
end
end
Player.Chatted:Connect(CheckMessage)
Nobody really does it like that. Most of the time its done this way:
game.Players.PlayerAdded:Connect(function(Player)
--- Script to run
end)
Also @Waum_a Most of what @ImTheBuildGuy has said has already been provided. @ImTheBuildGuy please dont post about common script knowlage that everyone will know, make it more specific to the task at hand.
Edit:
There are pages full of useful information. This is how roblox show how its done:
PCount has not yet been defined.
At the moment PCount will be nil because you haven’t made it a variable.
Meaning PCount when called will be nil because it doesn’t exist.
You will need to do:
local PCount = 0
Before the event (where it says game.Players.PlayerAdded)
Simply hook the function to make the NPC move in a Chatted event for when the player joins.
Example–
local players = game:GetService("Players")
local listOfWordsToContinue = {
[1] = "done!", -- MAKE ALL WORDS LOWERCASE.
[2] = "done"
}
players.PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(message)
for i = 1, #listOfWordsToContinue do
if (string.lower(message) == listOfWordsToContinue[i]) then
-- Handle NPC here.
end
end
end)
end)