What do you want to achieve? So, I want the messages a user says in chat to appear after the countdown ends on a ScreenGui.
What is the issue? Well, it just won’t show the messages on the ScreenGUI and the TextLabel.
What solutions have you tried so far? No, but I used the Assistant, but it wasn’t much help.
local Part = script.Parent
local Players = game:GetService("Players")
local ClickDetector = Part:WaitForChild("ClickDetector")
local function startCountdown(player)
local tv = workspace:WaitForChild("Wall Mount TV")
local lighting = game:GetService("Lighting")
local frame = tv:WaitForChild("TV")
local display = frame:WaitForChild("Display")
local play = display:WaitForChild("Play")
local timerGui = display:WaitForChild("SurfaceGui")
local soundService = game:GetService("SoundService")
local currentSound = soundService:FindFirstChildWhichIsA("Sound")
if currentSound and currentSound.Playing then
currentSound:Pause()
end
local newSound = Instance.new("Sound")
newSound.SoundId = "rbxassetid://17412699795" -- Song ID (notes to myself)
newSound.Parent = soundService
newSound:Play()
workspace["Day/Night Cycle"].Enabled = false
lighting.TimeOfDay = 24
lighting.Brightness = 0
for count = 311, 0, -1 do
timerGui.ImageLabel.Visible = false
timerGui.TextLabel.Text = count .. " seconds"
wait(1)
end
timerGui.ImageLabel.Visible = false
newSound:Pause()
workspace["Day/Night Cycle"].Enabled = true
lighting.Brightness = 1
-- Chat messages after countdown :D
timerGui.TextLabel.Text = "Countdown ended! Please wait..."
wait(1)
local targetUser = "PaytonPlayz8604" -- Username (notes to myself)
local TextChatService = game:GetService("TextChatService")
TextChatService.MessageReceived:Connect(function(message)
local senderId = message.SenderUserId
local sender = Players:GetPlayerByUserId(senderId)
if sender and sender.Name == targetUser then
print("Received message from " .. targetUser .. ": " .. message.Content)
timerGui.TextLabel.Text = message.Content
end
end)
end
ClickDetector.MouseClick:Connect(startCountdown)
Hmm… there are some mistakes on the code. You cannot receive messages from the TextChatService from the server. As the documentation says: This event is only fired on the client.
With that been said, you’ll need to:
a) Create a RemoteEvent (and name it Announce or anything else, but you’ll need to change the variables in the scripts) at ReplicatedStorage.
b) Create a local script (perhaps in the StarterPlayerScripts) and write some code to receive the messages.
c) Remove the script from the part and add it to the ServerScriptService.
An Example of the Script you can make at StarterPlayerScripts
local TextChatService = game:GetService("TextChatService")
local Announce = game:GetService("ReplicatedStorage"):WaitForChild("Announce") -- This will be used to fire the message to the server
TextChatService.OnIncomingMessage = function(message: TextChatMessage)
if message.TextSource then
if message and message.Status == Enum.TextChatMessageStatus.Success then
Announce:FireServer(message.Text)
end
end
end
In the script you provided I editied some stuff so it’s more legible . (and added so it receives the message from the client)
local Players = game:GetService("Players")
local Announce = game:GetService("ReplicatedStorage"):WaitForChild("Announce")
local Part = workspace:FindFirstChild("Part")
local ClickDetector = Part:WaitForChild("ClickDetector")
local tv = workspace:WaitForChild("Wall Mount TV")
local lighting = game:GetService("Lighting")
local frame = tv:WaitForChild("TV")
local display = frame:WaitForChild("Display")
local timerGui = display:WaitForChild("SurfaceGui")
local soundService = game:GetService("SoundService")
local currentSound = soundService:FindFirstChildWhichIsA("Sound")
local targetUser = "PaytonPlayz8604" -- Username (notes to myself)
local TextChatService = game:GetService("TextChatService")
local function startCountdown()
if currentSound and currentSound.Playing then
currentSound:Pause()
end
local newSound = Instance.new("Sound")
newSound.SoundId = "rbxassetid://17412699795" -- Song ID (notes to myself)
newSound.Parent = soundService
newSound:Play()
workspace["Day/Night Cycle"].Enabled = false
lighting.TimeOfDay = 24
lighting.Brightness = 0
for count = 311, 0, -1 do
timerGui.ImageLabel.Visible = false
timerGui.TextLabel.Text = count .. " seconds"
wait(1)
end
timerGui.ImageLabel.Visible = false
newSound:Pause()
workspace["Day/Night Cycle"].Enabled = true
lighting.Brightness = 1
-- Chat messages after countdown :D
timerGui.TextLabel.Text = "Countdown ended! Please wait..."
wait(1)
Announce.OnServerEvent:Connect(function(client_plr, message)
if client_plr.Name == targetUser then
print("Received message from " .. targetUser .. ": " .. message)
timerGui.TextLabel.Text = message
end
end)
end
ClickDetector.MouseClick:Connect(startCountdown)
Notes:
Placed all the variables on the top of the script
Removed the play variable as it wasn’t used in the script
Removed the player argument from the startCountdown function as it’s not needed.
Side Note: 311 seconds are a lot for a cooldown (It’s around 5 mins)
Hope this helped you, if you have any other questions let me know!