Hi all,
I am facing an issue with updating the text in my Roblox game’s GUI using a RemoteEvent
. The goal is to animate a title text in the menu when the RemoteEvent
is triggered by a TextButton
within the GUI.
The text doesn’t appear to be received by the client. Only the starting text seems be received once (as expected).
Below is a breakdown of the problem.
Steps to Reproduce:
- The
TextButton
fires aRemoteEvent
calledUpdateMenuText
with a string value that should update the text in the player’s menu GUI. - The client listens for this event and runs a function to animate the text in the menu.
- The
RemoteEvent
is being fired, but the Handler Script is not updating/receiving the text.
Expected Behavior:
- When the
RemoteEvent
is fired, the client should receive the text and animate it properly. - The text should smoothly update with an animation that reveals the full message one character at a time.
Actual Behavior:
- The event is triggered, the text is fired, but the Handler Script doesn’t receive the text.
- However, the text does not update visually on the GUI as expected, and no animation is played.
I’ve been trying to fix this for ages now, it might be the smallest thing I’ve missed. I’ve even thrown it ChatGPT’s way and it hasn’t fixed it.
I know the scripts are a little inefficient now but I’ve been trying everything I know to fix it.
I can post a video/screenshots of the menu and its hierarchy if needed.
Thanks all!
Scripts below🔽
Button Script (Local Script):
local textButton = script.Parent -- The TextButton the player clicks to open the settings menu
local hoverSound = textButton:FindFirstChild("Hover")
local clickSound = textButton:FindFirstChild("Click")
local hoverColor = Color3.fromRGB(255, 255, 255) -- Default text color (white)
local normalColor = Color3.fromRGB(200, 200, 200) -- Hover text color (light gray)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UpdateMenuText = ReplicatedStorage:WaitForChild("UpdateMenuText")
local SettingsMenu = textButton.Parent.Parent.Settings
local Music = textButton.Parent.Parent.Music
local EQ = Music["EQ AJST"]
EQ.Enabled = false
-- Bool value for knowing if the settings menu is opened or not
local OpenCloseBool = SettingsMenu:WaitForChild("Open/Close")
local function onButtonClick()
local targetText -- Declare the targetText variable
if OpenCloseBool.Value then
-- If 'Open/Close' bool is true, close the settings menu
SettingsMenu.Visible = false
OpenCloseBool.Value = false
EQ.Enabled = false
Music.Volume = 0.3
-- Set the text to be fired when closing
targetText = "TrainGuy196's Menu Testing Place"
else
-- If 'Open/Close' bool is false, open the settings menu
SettingsMenu.Visible = true
OpenCloseBool.Value = true
EQ.Enabled = true
Music.Volume = 0.13
-- Set the text to be fired when opening
targetText = "TrainGuy196's Settings"
end
-- Fire UpdateMenuText to update the text and print the fired text
UpdateMenuText:FireServer(targetText) -- Pass the text you want here
print("Fired text:", targetText) -- Print the exact text being fired
if clickSound then
clickSound:Play()
end
end
local function onMouseEnter()
if hoverSound then
hoverSound:Play()
end
textButton.TextColor3 = hoverColor -- Change text color on hover
end
local function onMouseLeave()
textButton.TextColor3 = normalColor -- Reset text color when the mouse leaves
end
textButton.MouseButton1Click:Connect(onButtonClick)
textButton.MouseEnter:Connect(onMouseEnter)
textButton.MouseLeave:Connect(onMouseLeave)
Handler Script (Local Script):
local Player = game.Players.LocalPlayer
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local LoadEvent = ReplicatedStorage:WaitForChild("LoadMainMenu")
local UpdateMenuText = ReplicatedStorage:WaitForChild("UpdateMenuText")
-- Wait for the menu GUI to be added to the PlayerGui
local MenuScreenGUI = Player:WaitForChild("PlayerGui"):WaitForChild("Menu")
local Backdrop = MenuScreenGUI.Backdrop
local Music = Backdrop.Music
local MenuText = Backdrop["Text/Button"].MainText
local TextSound = MenuText.Sound
local lastText = "" -- Variable to track the last animated text
-- Function to animate the text with a typing effect
local function animateText(targetText, delay)
local currentText = "TrainGuy196's "
MenuText.Text = currentText -- Set initial text to "TrainGuy196's"
-- Stop the current animation (if any)
local currentTween = MenuText:FindFirstChild("Tween")
if currentTween then
currentTween:Cancel()
currentTween:Destroy()
end
-- Animate the starting text ("TrainGuy196's")
for i = 1, #currentText do
MenuText.Text = string.sub(currentText, 1, i)
TextSound:Play()
task.wait(delay) -- Wait for the delay before adding the next letter
end
-- Animate the additional text after "TrainGuy196's"
for i = 1, #targetText do
MenuText.Text = "TrainGuy196's " .. string.sub(targetText, 1, i)
TextSound:Play()
task.wait(delay) -- Wait for the delay before adding the next letter
end
end
local function Load()
Music:Play()
MenuScreenGUI.Enabled = true
animateText("Menu Testing Place", 0.06) -- Animate the initial text on menu load
end
local lastText = ""
local function updatetext(targetText)
if targetText and type(targetText) == "string" and targetText ~= lastText then
print("Received target text:", targetText) -- Debugging print
animateText(targetText, 0.06) -- Animate the text based on the received target text
lastText = targetText -- Update lastText to prevent repeating animation
else
print("Error: targetText is nil or the same as the last text.")
end
end
UpdateMenuText.OnClientEvent:Connect(updatetext)
LoadEvent.OnClientEvent:Connect(Load)