I need help making this TextBox system work, please. So I have a TextBox, TextButton, and TextLabel. I am trying to make it so that when the player types in the textbox and presses the button that text will appear on the text label for everyone and have a typewriter sort of effect. I tried connecting it to a Remote Event but that did not help. Here is the LocalScript inside of the frame with the gui’s
local TextBox = script.Parent.TextBox
local RemoteEvent = game:GetService("ReplicatedStorage"):WaitForChild("SendMsg")
--local Text = script.Parent:WaitForChild("TextBox").Text
local TextLabel = script.Parent:WaitForChild("TextLabel")
local text = TextBox.Text
local sendmsg = game.ReplicatedStorage:WaitForChild("SendMessageToServer")
TextBox.FocusLost:Connect(function(enterPressed)
if not enterPressed then
return
end
sendmsg:FireServer()
end)
Inside ServerScriptService to handle the remote event:
local SendMessageToServer = Instance.new("RemoteEvent")
SendMessageToServer.Name = "SendMessageToServer"
SendMessageToServer.Parent = game.ReplicatedStorage
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel
local TextBox = game.StarterGui.ScreenGui.Frame5.TextBox
--local Text = script.Parent:WaitForChild("TextBox").Text
local TextLabel = game.StarterGui.ScreenGui.Frame5.TextLabel
local text = TextBox.Text
local function sendmsg()
for i = 1, #text, 1 do
TextLabel.Text = string.sub(text, 1, i)
wait(0.05)
TypeSound:Play()
end
end
SendMessageToServer.OnServerEvent:Connect(sendmsg)
I do not know how to make this work. Could someone help please? I have tried looking for other solutions but I don’t think I could find any related to my problem. Any help or guidence appreciated.
I am trying to write different stuff now to see if I can fix what I thought was the problem and get the error “attempt to get length of a Instance value”. Here is the updated code
Server Script
local SendMessageToServer = Instance.new("RemoteEvent")
SendMessageToServer.Name = "SendMessageToServer"
SendMessageToServer.Parent = game.ReplicatedStorage
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel
local function sendmsg(object,text,length)
for i = 1,#text,1 do
object.Text = string.sub(text,1,i)
wait(0.05)
TypeSound:Play()
end
end
SendMessageToServer.OnServerEvent:Connect(function(player, Textbox)
sendmsg(Textbox, Textbox.Text, 0.05)
end)
SendMessageToServer.OnServerEvent:Connect(sendmsg)
Local Script
local TextBox = script.Parent.TextBox
local Textbox = TextBox
local sendmsg = game.ReplicatedStorage:WaitForChild("SendMessageToServer")
script.Parent.TextButton.MouseButton1Click:Connect(function()
sendmsg:FireServer(Textbox)
end)
local TextBox = script.Parent.TextBox
local sendmsg = game.ReplicatedStorage:WaitForChild("SendMessageToServer")
script.Parent.TextButton.MouseButton1Click:Connect(function()
sendmsg:FireServer(TextBox, 0.05)
end)
Server Script
local SendMessageToServer = Instance.new("RemoteEvent")
SendMessageToServer.Name = "SendMessageToServer"
SendMessageToServer.Parent = game.ReplicatedStorage
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel
SendMessageToServer.OnServerEvent:Connect(function(player, TextBox, interval_length)
-- Get the initial Text value from the TextBox.
text = TextBox.Text
-- Iterate through each letter in the Text string.
for index, letter in ipairs(text)
TextBox.Text = string.sub(text, 1, index)
wait(interval_length)
TypeSound:Play()
end
end)
I had to try to patch up the code you gave me since it gave a few errors in the lines. But I tried to make it work. The server script script
local SendMessageToServer = Instance.new("RemoteEvent")
SendMessageToServer.Name = "SendMessageToServer"
SendMessageToServer.Parent = game.ReplicatedStorage
local TextBox = game.StarterGui.ScreenGui.Frame5.TextBox
local TypeSound = game.StarterGui.ScreenGui.Frame5.TextLabel.TypeSound
SendMessageToServer.OnServerEvent:Connect(function(player, TextBox, interval_length)
-- Get the initial Text value from the TextBox.
local text = TextBox.Text
-- Iterate through each letter in the Text string.
for index, letter in ipairs(text) do
TextBox.Text = string.sub(text, 1, index)
wait(interval_length)
TypeSound:Play()
end
end)
When I playtested and pressed the button it returned " ServerScriptService.GetMsg:12: invalid argument #1 to ‘ipairs’ (table expected, got string)" And when I tried your original script it just returned “infinite yield possible on ‘ReplicatedStorage:WaitForChild(“SendMessageToServer”)’”
Okay, I changed that line and when I pressed the button it didn’t show any error but also didn’t change the text label. And on line 9 I don’t know if I’m supposed to put a local there or not but without local behind it it just has an error underneath “text”.
You cannot set the value of TextBox from the Server script this way because this is handled on the Client side. Remote Events can be used for one-way communication from the Server to the Client.
You are passing an Instance of TextBox to the Server side, but once you pass this Instance to the Server side, it is essentially a new object, meaning that it is not the same Instance that you are trying to update on the client side. If you fire a Remote Event from the Client to the server, you can update the TextBox on the client side using your LocalScript.
I don’t think I explained it well enough but I am trying to grab the text input from the textbox and put it in the Text label and replicate it to all other clients. Is this what the script is supposed to do it looks like it’s trying to change the text box’s text. Thanks for helping.
Yes, you will need to use a Remote Event and connect it with a function that will update the Text Label’s text in a Local Script. You will need to communicate actions from the Server to the Client. I think I phrased my response incorrectly, but the overall concept is the same.