Pre-Chat V1 | Chat without typing!

Is pre-chat just a remake of old Roblox chat? Would probably only be nice to recreate older games but thats it.

1 Like

Also*** Can you spam with it? [That can be a issue]

1 Like

image

Please make one central local script that creates and connects to all the buttons

-- Example (this is just a reference of what you *could* do, not a drag and drop)

-- A function that adds a button to the chat list
local function CreateButton(chatString: string)
   local button = Instance.new("TextButton")
   -- yada yada
   ------------
   button.MouseButton1Click:Connect(function()
       -- send the message (this only works locally, so you would need to use remotes to replicate it to the server)
       Chat:Chat(Character.Head, chatString)
       StarterGui:SetCore("ChatMakeSystemMessage", { Text = `[{Player.Name}]: {chatString}` })
   end)
end

CreateButton("GG!") -- Creates a new chat button that makes the player say "GG!"

  1. You cannot access LocalPlayer from the server
  2. This doesn’t clone the UI; it just moves it. Meaning, after one player has it, no other player can receive it
1 Like

Basically, Super Safe Chat remade? :sweat_smile:

1 Like

Average devforum resource


3 Likes

I suggest you to learn scripting before making a resource, as theres alot of useful resources which gets mixed up with resources like this and its gets harder and harder to find that required useful resource.

5 Likes
  1. Just no
  2. The whole ‘judging’ premise here is based off the OP uploading the code implying that it’s theirs
3 Likes

:speech_balloon:
image

3 Likes

9 Likes

Nahh :skull: :rofl:

tu l’avais dĂ©jĂ  poster sur le server de codelow en + c’était un flop et mtn sur devfourm :rofl: tu t’es fait juste cook la @Ethanytb250

C’est bien de rĂ©pondre sur des posts anglais, surtout je crois que tu es le gars sur Discord appeller El:ectrique baahhaha, surtout tu vole des freemodels

In a respectable way. If you steal someone’s code and pretend that it’s completely yours and you made it from scratch, now that’s very disrespectful and not true.

I make sure to credit people if I have taken their publicly released code and used it in many ways.

Are you sure the server script works? As I saw you changed it to server script in serverscriptservice, so localplayer won’t work.

idk, i didn’t do anyting bro, wdym


There is a localscript in each button. This structure is bad

Your making your text message from core gui in the client, that wouldn’t reflect to other clients i think

  1. I don’t think this is allowed.
  2. Everything is client-sided, you should have tried your product before posting it.
  3. Most of the code has a lot of flaws such as:
  • No cooldown
  • Not replicating
  • The UI isn’t good
  • No character added updates
  • You are using multiple scripts instead of a Core script.

You are making a community resource. The source should be the first thing you should have posted.
It would be best if you learned the basics.

1 Like

image
The open button doesnt have a closing function

2 Likes

I mean this in the least harsh way, but I don’t think you’re qualified for making a Community Resource yet.
Since I was at your stage at one point, I’m going to help you.
Here’s what you can change to improve your Pre-Chat script:
Firstly, add a RemoteEvent to ReplicatedStorage called “Prechat”
Next, you should add a script to ServerScriptService, call it something like “PrechatRecieve”

Once you have done that, I want you to paste in this code and read the comments, really study this code:

local Remote = game.ReplicatedStorage:WaitForChild("Prechat")
local Players = game:GetService("Players")
local CooldownDuration = .75 -- How long of a cooldown you want between each message a player can send.
local Cooldown = {}
local AllowedMessages = {
	-- We associate a message with an ID so exploiters cannot use non-existing messages and send obscene messages
	[1] = "Hello!",
	[2] = "Yes.",
	[3] = "No.",
	[4] = "How are you?",
	[5] = "Good.",
	[6] = "Bad.",
	[7] = "Okay.",
	[8] = "Got it.",
	[9] = "I am planting the C4 at Bombsite B."
	-- You can add more messages to the list but make sure to increment the number.
}

Players.PlayerAdded:Connect(function(Player)
	-- Add a new player object to the cooldown list
	Cooldown[Player.UserId] = tick()
	-- Tick gets the current second with decimal place
	-- We get the ID of the player and add it to the Cooldown list
end)

Players.PlayerRemoving:Connect(function(Player)
	Cooldown[Player] = nil -- Removes the player from the cooldown list so we don't encounter a memory leak
	-- A memory leak is when more data is exponentially used and is not disposed.
end)

Remote.OnServerEvent:Connect(function(Player, ID)
	local Message = AllowedMessages[ID]
	if Message then -- This checks whether the message is real and existing
		local LastMessage = Cooldown[Player.UserId] -- Gets the last time the player has sent a message.
		
		if tick()-LastMessage>CooldownDuration then
			-- Great! We can now send the message to all clients.
			print("Recieved and sending.") -- You can remove this print statement if you wish.
			Remote:FireAllClients(Player, Message)
			Cooldown[Player.UserId] = tick() -- Resets the timer
		else
			Remote:FireClient(Player, "Sorry! You are on cooldown for sending Prechat messages.")
			-- Informs the player that they are on cooldown.
		end
	end
end)

Great, we can now receive messages as the server and verify them and send them back to the client, this is going good so far.

Working screenshot:
image
Error below is unrelated and from a plugin

Now we have to setup a client, which is easier said than done, but I’ll do that hard work for you and all you have to do is study the code and read the comments. Call the LocalScript “PrechatClient”

local Remote = game.ReplicatedStorage:WaitForChild("Prechat")
local Chat = game:GetService("Chat")

Remote.OnClientEvent:Connect(function(Sender:Player,Message)
	-- This fires when the server sends the message to the client.
	if Sender and Sender.Character then
		-- Checks that the sender has a character
		local Head = Sender.Character:FindFirstChild("Head")
		if Head then
			Chat:Chat(Head,Message) -- Displays the message
			-- You can use DisplaySystemMessage but that isn't working for me right now, so you will have to do that on your own.
		end
	end
end)

Add the client script to StarterPlayerScripts and voila, we have the main handler.
Let’s see what it looks like when we send the message using the Command Line
image


loud silence
Wait, we need the UI to properly send the messages!
Let’s set up a basic message sending UI.
It should follow this order in Explorer:
image
The buttons are named based on their message ID, which is in the PrechatRecieve script, in ServerScriptService. This is not the best way to do this, but it’ll work for the sake of this walk-through. You also do not need a UIGridLayout, but I’m doing it so I can be lazy and not do the UI.

Add a LocalScript to the parent of buttons, which in my case is a frame.
Name the LocalScript something along the lines of Messaging, as it will serve the purpose of messaging the server.

Yet again, I want you to study this code and read ALL of the comments in detail.

local Remote = game.ReplicatedStorage:WaitForChild("Prechat")

wait(1) -- Waits for all the UI to load

for _,v in pairs(script.Parent:GetChildren()) do
	-- Loops through all of the children of the frame
	if v:IsA("TextButton") then
		-- Checks whether the child is a button, so it doesn't detect the script or the layout
		v.MouseButton1Click:Connect(function()
			-- Fires whenever it gets clicked.
			Remote:FireServer(tonumber(v.Name)) -- Sends a message to the server.
		end)
	end
end

Works like a charm!

I have updated it and fixed the issue where you could only send one message.

4 Likes

I have now put this into a bundle which you can import by pressing the Model button:
PrechatFixedBundle.rbxm (10.3 KB)
image

2 Likes