Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

A more efficient way to change text?

Asked by 6 years ago

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?

0
You could pass the text that you want it to display as a parameter PoePoeCannon 519 — 6y

1 answer

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
6 years ago

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)
0
Okay, that works. but it won't work when i try to change the text a 2nd time GamingOverlord756 48 — 6y
0
nvm it worked. Thank you! GamingOverlord756 48 — 6y
Ad

Answer this question