Is pre-chat just a remake of old Roblox chat? Would probably only be nice to recreate older games but thats it.
Also*** Can you spam with it? [That can be a issue]
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!"
- You cannot access
LocalPlayer
from the server - This doesnât clone the UI; it just moves it. Meaning, after one player has it, no other player can receive it
Basically, Super Safe Chat remade?
Average devforum resourceâŠ
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.
- Just no
- The whole âjudgingâ premise here is based off the OP uploading the code implying that itâs theirs
Nahh
tu lâavais dĂ©jĂ poster sur le server de codelow en + câĂ©tait un flop et mtn sur devfourm 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
- I donât think this is allowed.
- Everything is client-sided, you should have tried your product before posting it.
- 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.
The open button doesnt have a closing function
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:
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
âŠ
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:
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.
I have now put this into a bundle which you can import by pressing the Model button:
PrechatFixedBundle.rbxm (10.3 KB)