You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? To get a way of alerting everyone on the server that there is a fire.
What is the issue? So I’m making a script that will send an alert to all players, whether it be a chat message or gui that comes up. I’ve got another script that will update a Boolean value called “FireActive” to true when the fire starts. The know the script works and the function works since I get a message in cmd saying “There is a fire!”. But the chat message doesn’t work. From what I’ve looked up, it needs to a localscript for it to work, however if I set it as a localscript it doesn’t run at all. The “FireActive” and the code bellow is in the models group.
What solutions have you tried so far? I’ve looked online and haven’t found anything, I’ve also asked the roblox assistant.
-- Script for sending out a serverwide notification when FireActive is true
parent = script.Parent
local function sendAlert()
print("There is a fire!")
game:GetService("StarterGui"):SetCore("ChatMakeSystemMessage", {
Text = "Fire alert! Fire detected at: "..parent.Name,
Color = Color3.fromRGB(255, 0, 0),
Font = Enum.Font.SourceSansBold,
FontSize = Enum.FontSize.Size24
})
end
while true do
if parent.FireActive.Value == true then
sendAlert()
wait(100)
else
print("fire not started yet")
wait(12)
end
end
You should track when the fire starts on the server. And I’d recommend not using a boolvalue because uh I think it takes up more memory or smthn like that
Then you should create a RemoteEvent and use FireAllClents
Then you can use StarterGui:SetCore
You should prolly imo use a wait task.wait() loop
I’ll give you a lil example:
-- ON THE SERVER (ServerScriptService)
local RE = path.to.remote
-- detect when the fire starts
--[[
i saw you had a parent property, I’m not sure what that could be though so I’ll assume
that you can get it on the server
]]
RE:FireAllClients(parent)
Hi, many thanks for the response. So I have a script in serverscriptservice that picks a random building and then it’ll set FireActive to true and set alight the building. So would you recommend I store whether a fire is active in that script then from there I send an alert, the only problem is that that script is not a local script. The parent property just links back to the parent so the name of the model so I’m able to tell where the fire is
Like @Doomcolp said, use a RemoteEvent, and connect a LocalScript in StarterPlayerScripts, or if you have a GUI for it as well, StarterGui. From there, you can interact with the Core Scripts.
Just a quick question: Are you using the new or old chat?
Yeah I think that, that would be more memory efficient even if it’s just a small optimization
Hm then you’d have to create a LocalScript or use an existing one along side the server Script
Gotchu, I thought it was a LocalScript at the time and just wanted to make sure you could still access whatever you needed to
If you’re using the new chat system, you’ll have to create a TextChannel and use TextChannel:SendAsync instead of StarterGui:SetCore("ChatMakeSystemMessage")
No, that’s not really how you would use it. It’s TextChannel:DisplaySystemMessage(), and you could just use the default text channels. That’s all I was checking for, just in case @AtheonsYoshi was using an old chat interaction on the new chat.
No, don’t change it back. It’s simpler on the new one. To display the message to everyone, e.g. in the main TextChannel, you can do the following (in a LocalScript):
local tcs = game:GetService("TextChatService")
tcs.TextChannels.RBXGeneral:DisplaySystemMessage("Message content here")
What you have currently will work on the old chat.
Many thanks I’ve got it working. However, I’m struggling to get it to also show where the building is located. I’ve added some code to get it to make a new string and sent it to replicated storage that has the value of the building picked, this works I can see that when testing. But the code to send a message only shows whats in “”
local tcs = game:GetService("TextChatService")
game.ReplicatedStorage.Fire.OnClientEvent:Connect(function()
tcs.TextChannels.RBXGeneral:DisplaySystemMessage("FIRE LOCATED IN: ", game.ReplicatedStorage.Building.Value)
end)