Server Chat Help

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.

  1. 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,

  2. 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.

Kindest regards,
Waum_a.

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)
1 Like

image

I said to put it in a player added function in a server script

1 Like

I put it into a NPC, so when the they chat “Done!” the NPC moves, also What do you mean by"PlayerAdded function"?

Do you mean

game.Player.Added, etc

?

Issue here is If i say ‘Done!’ more than once it will still count, so one player could make the NPC move before players are ready.

EDIT:
You will need to log the players that have already said ‘Done!’ and prevent it from adding to the total.

True but I can fix it, I think.

Ohhhhhhhhhhhhhhhhhhh, I now understand you, yes that will be a problem.

game.Players.PlayerAdded:Connect(INSERT FUNCTION NAME HERE)

This.

Not too much though. You can still get both the player and the message, just means adding in a list and checking for the player.

Source:

game.Players.PlayerAdded:Connect(function(player)
  player.Chatted:Connect(function(msg)
        -- do stuff with msg and player
  end)
end)
1 Like

image

did you actually make a function though?

function dab()
print("dab")
end

game.Players.PlayerAdded:Connect(dab)

And what function is for that code?

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:

1 Like

image

I supposed this goes by this way, Idk. image

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)

1 Like

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)
1 Like