Npc in my lobby sometimes stops working for specific players

i have this npc in my lobby and the lobby is put into serverstorage and then placed back in workspace once the game is over and sometimes the npc’s chat doesnt show for other players until another game cycle even though its all in a server script

the code for the npc:

local character = script.Parent.Parent.Parent
local talkPart = character:WaitForChild("Head")
local functionLibrary = require(game.ServerScriptService.FunctionLibrary)
local prompt = script.Parent
local cooldown = false
prompt.Triggered:Connect(function(player)
	if cooldown == false then

	local random = math.random(1, 5)
	if random == 1 then
		functionLibrary.Chat(talkPart, "Custom", "Please don't die out there.")
		elseif random == 2 then
			functionLibrary.Chat(talkPart, "Custom", "Some strong foes have a chance to drop a weapon for you!")
		elseif random == 3 then
			functionLibrary.Chat(talkPart, "Custom", "Some enemies may be a hindrance to their fellow companions.")
		elseif random == 4 then
			functionLibrary.Chat(talkPart, "Custom", "Please don't go out there without a healer, you may regret it.")
		elseif random == 5 then
			functionLibrary.Chat(talkPart, "Custom", "The more damage you deal to an enemy the more money you'll gain after they die!")
		elseif random == 6 then
			functionLibrary.Chat(talkPart, "Custom", "I can give you useful tips!")
		end

	end
end)
2 Likes

there is no difference but this just makes it alot easier for you.

local character = script.Parent.Parent.Parent
local talkPart = character:WaitForChild("Head")
local functionLibrary = require(game.ServerScriptService.FunctionLibrary)
local prompt = script.Parent
local cooldown = false
local messages = {
"Please don't die out there.";
"Some strong have a chance to drop a weapon for you!";
"Some enemies may be a hindrance to their fellow companions.";
"Please don't go out there without a healer, you may regret it.";
"The more damage you deal to an enemy the more money you'll gain after they die!";
"I can give you useful tips!";
}
prompt.Triggered:Connect(function(player)
	if cooldown == false then
	  functionLibrary.Chat(talkPart, "Custom", Random.new():NextInteger(1, #messages)
   end
end)
1 Like