im making an obby and when a player touches a part, i want the system to send a message
3 Likes
In a script that is parented to the part:
local part = script.Parent
part.Touched:Connect(function()
local touched = part:GetTouchingParts()
for i=1, #touched do
if touched[i].Parent:FindFirstChild("Humanoid") then
print("message")
end
end
end)
If you want to have it be an actual message on the screen instead of in the console, then you’d have to use a ScreenGui and have a TextLabel appear & output a message.
yeah i want the system to use chat like this
[Server] : xxx has beaten an obby
--server
event:FireAllClient({Text="[Server] : xxx has beaten an obby", Color=Color3.fromRGB(218, 65, 45)}) --example
--client
event.OnClientEvent:Connect(function(data)
game.StarterGui:SetCore("ChatMakeSystemMessage", data)
end)
--server
event:FireAllClient('<font color="rgb(255,125,0)">[Server]</font> : <b>xxx</b> has beaten an obby') --example
--client
event.OnClientEvent:Connect(function(data)
game.TextChatService:WaitForChild("TextChannels"):WaitForChild("RBXGeneral"):DisplaySystemMessage(data) --you can use RBXSystem too
end)
On the server(listening for the Touched event and notifying the clients):
--Server script in ServerScriptService
local Remote = Instance.new("RemoteEvent", game.ReplicatedStorage)
Remote.Name = "SystemChat"
local part = workspace.Baseplate --example
--message config
local config = {
Color = Color3.fromRGB(255, 0, 0),
Font = Enum.Font.Arial,
FontSize = Enum.FontSize.Size18
}
local touched = {} --who has already touched the part?
part.Touched:Connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if not player or table.find(touched, player) then return end
table.insert(touched, player)
local message = "[Server]: "..player.Name.." has beaten an obby!"
Remote:FireAllClients(message, config)
end)
On the client(picking up the notification and showing it depending on chat version):
--LocalScript
local TextChatService = game:GetService("TextChatService")
local StarterGui = game:GetService("StarterGui")
local Remote: RemoteEvent = game.ReplicatedStorage:WaitForChild("SystemChat")
type config = {Text: string?, Color: Color3, Font: EnumItem, FontSize: EnumItem}
local function configToRichtext(message: string, config: config): string
local hex = config.Color:ToHex()
local size = config.FontSize.Name:gsub("%D", "")
local format = "<font color='#%s'><font size='%d'><font face='%s'>%s</font></font></font>"
return format:format(hex, size, config.Font.Name, message)
end
Remote.OnClientEvent:Connect(function(message: string, config: config)
if TextChatService.ChatVersion.Name == "LegacyChatService" then
config.Text = message
StarterGui:SetCore("ChatMakeSystemMessage", config)
else
local system: TextChannel = TextChatService.TextChannels.RBXSystem
system:DisplaySystemMessage(configToRichtext(message, config))
end
end)
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.