What do you want to achieve? Keep it simple and clear!
I want that when you write an Announcement in the TextBox and click on the “Post” Button, a GUI should pop up showing the announcement, the Username and a headshot image of the Avatar.
What is the issue? Include screenshots / videos if possible!
The announcement doesn’t show/the texts and image doesn’t change to my headshot image, username and announcement
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have looked on the Forum, watched Youtube videos and even asked an AI for help but even the AI got overwhelmed.
Btw I don’t have very much experience with events + the AI made some changes on the script so it may be a bit confusing and messy (I like trying things out myself lol)
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
This is my localscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AnnouncementEvent = ReplicatedStorage.AnnouncementEvent
local plr = game.Players.LocalPlayer
local PostButton = plr.PlayerGui.StaffPanel.MainUI.Frame.PostButton
local TextBox = PostButton.Parent.TextBox
PostButton.MouseButton1Click:Connect(function()
if #TextBox.Text > 0 then
local username = plr.Name
local content = TextBox.Text
local image = "https://www.roblox.com/headshot-thumbnail/image?userId".. plr.UserId .."=1&width=420&height=420&format=png"
AnnouncementEvent:FireServer(username, content, image)
end
end)
And this is my Serverscript:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local AnnouncementEvent = ReplicatedStorage:WaitForChild("AnnouncementEvent")
local UserUI = ReplicatedStorage.Announcements.Frame.Username
local UserImage = UserUI.Parent.PlayerPicture
local ContentUI = UserUI.Parent.Post
local AnnouncementUI = UserUI.Parent
AnnouncementEvent.OnServerEvent:Connect(function(plr, username, content, image)
UserUI.Text = username
ContentUI.Text = content
UserImage.Image = image
AnnouncementUI.Visible = true
for _, player in pairs(game.Players:GetPlayers()) do
AnnouncementEvent:FireClient(player, AnnouncementUI)
end
wait(6)
AnnouncementUI.Visible = false
end)
Do you mean a script that receives the AnnouncementEvent:FireAllClients? If so, I don’t have one cuz I didn’t know that I needed one. I just have the serverscript that fires the Event and that’s this:
local AnnouncementEvent = ReplicatedStorage:WaitForChild("AnnouncementEvent")
local UserUI = game.StarterGui.Announcements.Frame.Username
local UserImage = UserUI.Parent.PlayerPicture
local ContentUI = UserUI.Parent.Post
local AnnouncementUI = UserUI.Parent
AnnouncementEvent.OnServerEvent:Connect(function(plr, username, content, image)
AnnouncementEvent:FireAllClients(plr, AnnouncementUI)
end)```
So I browsed a little bit through the devforum and changed some things in the script again and also added another localscript that receives the event again. Here’s all scripts again:
LocalScript (first script that fires the event)
local AnnouncementEvent = ReplicatedStorage.AnnouncementEvent
local AnnouncementUI = game.StarterGui.Announcements.Frame
local plr = game.Players.LocalPlayer
local UserUI = game.StarterGui.Announcements.Frame.Username
local UserImage = UserUI.Parent.PlayerPicture
local ContentUI = UserUI.Parent.Post
local PostButton = plr.PlayerGui.StaffPanel.MainUI.Frame.PostButton
local TextBox = PostButton.Parent.TextBox
PostButton.MouseButton1Click:Connect(function()
if #TextBox.Text > 0 then
local username = plr.Name
local content = TextBox.Text
local image = "https://www.roblox.com/headshot-thumbnail/image?userId".. plr.UserId .."=1&width=420&height=420&format=png"
AnnouncementEvent:FireServer(plr.Name, TextBox.Text, plr.UserId)
end
end)
ServerScript:
local AnnouncementEvent = ReplicatedStorage:WaitForChild("AnnouncementEvent")
local UserUI = game.StarterGui.Announcements.Frame.Username
local UserImage = UserUI.Parent.PlayerPicture
local ContentUI = UserUI.Parent.Post
local AnnouncementUI = UserUI.Parent
AnnouncementEvent.OnServerEvent:Connect(function(plr, Text)
UserUI.Text = plr.Name
UserImage.Image = "https://www.roblox.com/headshot-thumbnail/image?userId=".. plr.UserId .."1&width=420&height=420&format=png"
ContentUI.Text = Text
AnnouncementEvent:FireAllClients(UserUI, UserImage, ContentUI)
end)
Okay, yeah that makes sense. In the first localscript that detects if the player has clicked the “Post” button, I have changed the line that fires the event to this: AnnouncementEvent:FireServer(plr, Text) (I defined where the text is with local and changed TextBox.Text to just text but it still doesn’t seem to be working. I have read through the scripts again and it seems like everything is defined correctly (if I didn’t miss anything) so idk.
Sorry for bumping this topic but I just wanted to say that I found a solution myself. If anyone needs this:
Basically what I did was in the localscript I made a function that when a person clicks the “Post” button, it will edit the Announcement GUI with the text from the textbox, username and image of the player. then I just fired “Announcement posted” to the server to let it know that there is an announcement ready to be displayed. In the serverscript I then just enabled the announcementGUI. Here are the scripts if you need it:
Localscript:
SendButton.MouseButton1Click:Connect(function()
if #TextBox.Text >= 1 then
Username.Text = Player.Name
Post.Text = TextBox.Text
local userId = Player.UserId
local thumbType = Enum.ThumbnailType.HeadShot
local thumbSize = Enum.ThumbnailSize.Size100x100
local content, isReady = Players:GetUserThumbnailAsync(userId, thumbType, thumbSize)
PlayerPicture.Image = (isReady and content) or PLACEHOLDER_IMAGE
PlayerPicture.Size = UDim2.new(0, 100, 0, 100)
ReplicatedStorage.AnnouncementEvent:FireServer("Announcement Posted!")
end
end)
Serverscript:
ReplicatedStorage.AnnouncementEvent.OnServerEvent:Connect(function(player, a)
script.Parent.Enabled = true
wait(10)
script.Parent.Enabled = false
end)
Thanks to everyone for helping and sorry again for bumping this thread.
Edit: Just tested it with 2 players and it just edits it for 1 player. Sorry for that