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)
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…
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.
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
Using local will let you access the local player though
local Player = game:GetService('Players').LocalPlayer
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)
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.
-- 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