Hello everyone, my name is Tom. I am in-need of help for a specific line of code in my announcement system.
Disclaimer: Please note that I am not a scripter. Although, I acquire some knowledge. This post may be confusing. I deeply apologize for any inconvenience.
This is the current state of the Announcement UI in the ‘StarterGui’:
This is the design of the Announcement System:
The announcement is accessed by 2 ways:
- People that are added on the ‘Admin list’ can access it.
- By Group: people with a specific Group rank and above can access it.
The issue that I am trying to fix has to do with the ‘PlayerName’ TextLabel found in:
StarterGui > AnnouncementGui > AnnouncementFrame > PlayerName
Explanation: Whenever a person with access sends an announcement (either by them being added on the Admin List or having the Minimum Allowed group rank or above). The ‘AnnouncementFrame’ will show up with their Headshot, Username & Text for a specific duration (set by them).
The issue is that instead of showing the Player’s name that sent that announcement. It will show the Local Player’s name that is viewing that announcement.
Example: A player named ‘ROBLOX’ sends an announcement. Instead of showing “Announcement from ROBLOX”, it will show “Announcement from TomOMG25” (which is ME viewing the specific announcement).
The script can be found below:
AnnouncementCore local script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local client = Players.LocalPlayer
local event1 = ReplicatedStorage:WaitForChild("EnableAnnouncementSystem")
local event2 = ReplicatedStorage:WaitForChild("DisplayAnnouncement")
local event3 = ReplicatedStorage:WaitForChild("PlayerError")
local filterStringFunction = ReplicatedStorage:WaitForChild("FilterStringFunction")
local frame = script.Parent:WaitForChild("Frame")
local closeButton = frame:WaitForChild("CloseButton")
local postButton = frame:WaitForChild("EnterButton")
local inputBox = frame:WaitForChild("InputBox")
local tinputbox = frame:WaitForChild("TimeInputBox")
local title = frame:WaitForChild("Title")
local aframe = script.Parent:WaitForChild("AnnouncementFrame")
local loadbar = aframe:WaitForChild("LoadBar")
local announcement = aframe:WaitForChild("Announcement")
local PlayerImage = aframe:WaitForChild("PlayerImage")
local PlayerName = aframe:WaitForChild("PlayerName")
local function postButtonClicked()
if inputBox.Text == "" and tinputbox.Text == "" then
event3:FireServer("Type an announcement and a duration.")
wait(1) -- Wait for 1 second before changing the title
frame.Title.Text = "Announcements" -- Ensure this correctly references the Title object
return
end
if inputBox.Text == "" and tinputbox.Text ~= "" then
event3:FireServer("Type an announcement.")
wait(1)
frame.Title.Text = "Announcements"
return
end
if tinputbox.Text == "" and inputBox.Text ~= "" then
event3:FireServer("Type a duration.")
wait(1)
frame.Title.Text = "Announcements"
return
end
-- Filtering the input message for moderation
local input = inputBox.Text
local result, wasFiltered = filterStringFunction:InvokeServer(input)
if wasFiltered == false then
event2:FireServer(result, tinputbox.Text)
else
local Filtered = "(Server Message has been Moderated!)"
event2:FireServer(Filtered, tinputbox.Text)
end
end
event3.OnClientEvent:Connect(function(message)
title.Text = message
end)
local function closeButtonClick()
frame:TweenPosition(UDim2.new(-1, 0, 0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 0.6)
end
event1.OnClientEvent:Connect(function()
frame:TweenPosition(UDim2.new(0.2, 0, 0.4, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1)
end)
event2.OnClientEvent:Connect(function(message, duration, thumbnail_id)
local ClientDisplayName = client.DisplayName -- Get the local player's display name
local ClientUserName = client.Name -- Get the local player's username
PlayerName.Text = "Announcement from " .. ClientUserName
announcement.Text = message -- The actual announcement text
PlayerImage.Image = thumbnail_id -- Display the user's profile picture
script.Sound:Play()
aframe:TweenPosition(UDim2.new(0.5, 0, 0.1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
loadbar:TweenSize(UDim2.new(1, 0, 0.2, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
task.wait(1)
loadbar:TweenSize(UDim2.new(0, 0, 0.2, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, math.clamp(duration - 1, 1, math.huge), true)
task.wait(math.clamp(duration - 1, 1, math.huge))
aframe:TweenPosition(UDim2.new(0.5, 0, -1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 1, true)
task.wait(1)
end)
closeButton.MouseButton1Click:Connect(closeButtonClick)
closeButton.TouchTap:Connect(closeButtonClick)
postButton.MouseButton1Click:Connect(postButtonClicked)
postButton.TouchTap:Connect(postButtonClicked)
Any help is really appreciated! Thank you for reading!