Scripting an Announcement Gui

You can write your topic however you want, but you need to answer these questions:

So, I am trying to make a guy where someone puts text, its announces the text to all of the players.

Right now it currently works, but it doesn’t send the text, only their username and rank.

script.Parent.MouseButton1Click:Connect(function()
	local player = script.Parent.Parent.Parent.Parent.Parent
	local rank = player:GetRoleInGroup(9784808)
	local announcement = script.Parent.Parent.Type.Text
	
	game.ReplicatedStorage.RemoteEvents.sendAnnouncement:FireAllClients(player.Name, rank, announcement)
end)

Please help me. Thanks. :slight_smile:

2 Likes

Is this a server or local script?

server script.

ignore this part since Roblox says 30+ characters

how?

ignore this part since Roblox says 30+ characters

Just detect when the user has hit enter to submit the announcement, then use a remoteevent to send that text to the server.

… that’s what I’ve been doing.
When they click the submit button it sends the text through a remote event

Yes, but you need to get the text from the client to the server, right now you’re trying to get the text from a local gui using a server script and send it to all the players, which doesn’t work because that local gui text doesn’t exist serverside yet…

so how do I fix this??

ignore this part since Roblox says 30+ characters

Use a script to detect when enter is clicked, make sure the string isn’t empty. Use a RemoteEvent to send that text to your serverscript which will send the announcement out over whatever medium.

Move this to a local script, for 3 reasons

  1. It’s highly suggested to not use server scripts for UI elements; you are changing the client’s UI on the client, so just use a local one
  2. Using local will let you access the local player though
local Player = game:GetService('Players').LocalPlayer
  1. If you need to fire to all clients, just fire to the server, then when the server receives the event you can fire to all clients again
-- Client
local player = game:GetService('Players').LocalPlayer
local event = game.ReplicatedStorage.RemoteEvents:WaitForChild('sendAnnouncement')

script.Parent.MouseButton1Click:Connect(function()
    local announcement = script.Parent.Parent.Type.Text
    if announcement ~= nil then
	    local rank = player:GetRoleInGroup(9784808)
	    event:FireServer(rank, announcement)
    end
end)

-- Server
event.OnServerEvent:Connect(function(rank,ann)
    event:FireAllClients(rank,ann)
end)
3 Likes

:confused: :thinking: :confounded: I’m such a bad scripter.

You’re not a bad scripter, when you start out it’s difficult to understand the client-server boundary. You’ll figure it out as you progress.

ik but I don’t even understand you guys are saying.

Basically, all @lluckvy 's scripts do is grab the text from the textbox when the button is clicked, detect if there’s actually a string there using if announcement ~= nil (it wouldn’t make any sense to send an announcement if there wasn’t) then he checks the player’s rank and fires it to the server along with the string. Then, on the server, he grabs that data and fires it to the clients, which you can then detect when that happens and pull your announcement gui onto the screen with the data.

its to confusing. do any of you do tutoring lessons about this stuff?

With explanation

-- Client
local player = game:GetService('Players').LocalPlayer -- Retrieve the local player
local event = game.ReplicatedStorage.RemoteEvents:WaitForChild('sendAnnouncement') -- Remote event in ReplicatedStorage (use WaitForChild)

script.Parent.MouseButton1Click:Connect(function() -- Mouse clicked event, runs once fired
    local announcement = script.Parent.Parent.Type.Text -- Retrieves TextBox text
    if announcement ~= nil then -- If there's text written inside, then...
	    local rank = player:GetRoleInGroup(9784808) -- Returns RoleSet name in group
	    event:FireServer(rank, announcement) -- Fires event to the server
    end
end)

-- Server
event.OnServerEvent:Connect(function(rank,ann) -- Server receives event + arguments (rank and announcement)
    event:FireAllClients(rank,ann) -- Fires again to the client, this time it will be received by the GUI which will show to everyone
end)

By the way, do you have the script which receives the FireAllClients event? If so, could we see it?

If the player configures the text the server doesn’t detect any changes made to the text. You have to do a RemoteEvent and use the text the player inputted as a parameter, THEN do the announcement.

Also, use print() on the client side to see if when the remove event is fired they even get the text. From there we can dissect whether the issue occurs before or after the fireAllClients event

Found this and many more videos on YouTube, just search “announcement gui roblox”

1 Like

They already have a system, it just needs some work to fix it. No need for a whole new system.