Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

A more efficient way to change text?

I have a localscript, script, and a remote event the localscript fires the remote event when i press a textbutton (code below)

local text = game.ReplicatedStorage:WaitForChild("Text")
textlabel = script.Parent.Parent:WaitForChild("TextLabel")

textlabel.Text = text.Value --This is a string value.
text.Changed:Connect(function()
	textlabel.text = text.Value
end)

script.Parent.MouseButton1Down:Connect(function()
	game.ReplicatedStorage.TextChanger:FireServer()
end)

Just to be clear, the localscript is parented under the textbutton and "TextChanger" is a remote event under replicatedstorage text is also parented under replicatedstorage

Below is the code for the normal script

local function textchange1(player)
	game.ReplicatedStorage:WaitForChild("text").Value = "Hello"
end

game.ReplicatedStorage.TextChanger.OnServerEvent:Connect(textchange1)

Now i've been searching for ways, but i can't find how to change the value/text more than once using one remote event. Do i have to use multiple Remote Events in order to change the text multiple times?

1 comment

0

You could pass the text that you want it to display as a parameter

1 answer

✓ Accepted answer

Local script:

local text = game.ReplicatedStorage:WaitForChild("Text")
textlabel = script.Parent.Parent:WaitForChild("TextLabel")

local newtext = "hi"

textlabel.Text = text.Value --This is a string value.
text.Changed:Connect(function()
    textlabel.text = text.Value
end)

script.Parent.MouseButton1Down:Connect(function()
    game.ReplicatedStorage.TextChanger:FireServer(newtext) -- sends 'newtext' to the server receiver
end)

Server script:

local function textchange1(player, newtext)
    game.ReplicatedStorage:WaitForChild("text").Value = newtext -- set the value to 'newtext'
end

game.ReplicatedStorage.TextChanger.OnServerEvent:Connect(textchange1)

2 comments

0

Okay, that works. but it won't work when i try to change the text a 2nd time

0

nvm it worked. Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.