I’m trying to make a GUI that when clicked sends a message in chat for the player.
For example if I put a button with an emoji and one clicks it I want in the chat to be: [ironboy1965]:
But I want it to be instant at the click of the button without having to hit enter.
I trying using system messages but I cant get to write the name of the player like in a normal chat. I’m not sure what I’m supposed to use for this and there is little to no documentation from Roblox.
--Variables
local Chat = game:GetService("Chat")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent.TextButton
--Functions
Button.MouseButton1Click:Connect(function()
Chat:Chat(Char:WaitForChild("Head"),"Thank you")
game.StarterGui:SetCore("ChatMakeSystemMessage",{
Text = "{System}Thank you "..Player.Name.." for clicking on the button1";
})
end)
I guess you got your script off youtube, which isn’t a problem, but first you should understand how it works, and only then use it.
Your script will look like this:
--Variables
local Chat = game:GetService("Chat")
local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Button = script.Parent.TextButton
--Functions
Button.MouseButton1Click:Connect(function()
Chat:Chat(Char:WaitForChild("Head"),"Thank you")
game.StarterGui:SetCore("ChatMakeSystemMessage",{
Text = "["..Player.Name.."]: ABC"; --change ABC to the text you want the player to send
})
end)
Also, this is a LocalScript, so only you will see the message. Change it to a ServerScript if you want every player to see it
I tried to make it server but it gives to me this error and the message didn’t appear on the chat but only on the bubble:
StarterGui:SetCore must be called from a local script. - Studio
local Button = script.Parent
local Event = Button.RemoteEvent
Button.MouseButton1Click:Connect(function()
Event:FireServer("Test")
end)
--Variables
local Chat = game:GetService("Chat")
local Event = script.Parent.RemoteEvent
Event.OnServerEvent:Connect(function(x, argument)
local Char = x.Character
if argument == "Test" then
Chat:Chat(Char:WaitForChild("Head"),"👮")
game.StarterGui:SetCore("ChatMakeSystemMessage",{
Text = "["..x.Name.."]: ABC"; --change ABC to the text you want the player to send
})
end
end)
Its going to be the same. So you will have the event handler something like this:
local Chat = game:GetService("Chat")
... function(player)
local char = player.Character -- you can also just pass the character as an argument, it might be easier
Chat:Chat(char:WaitForChild("Head"),"👮")
end)
I never worked with the chat service either, but it should work