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

Why isn't LocalScript updating TextLabel?

Hi, I'm trying to set up two ScreenGuis with TextLabels inside that indicate the amount of "kills" and "tries" the player has. I set up a LocalScript in each ScreenGui that, upon receiving a RemoteEvent (called either ChangeTriesText or ChangeKillsText), will change the text of their TextLabel. This is my code:

Change Tries

local message
game.ReplicatedStorage.ChangeTriesText.OnClientEvent:Connect(function(value)
	message = tostring("Chances: ".. tostring(value))
	script.Parent.TextLabel.Text = message
	print(script.Parent.TextLabel.Text)
end)

Change Kills

local message
game.ReplicatedStorage.ChangeKillsText.OnClientEvent:Connect(function(value)
	message = tostring("Kills: ".. tostring(value))
	script.Parent.TextLabel.Text = message
	print(script.Parent.TextLabel.Text)
end)

The scripts do receive the RemoteEvents, and they both print the appropriate strings. However, the TextLabels do not change their text. I'm at a loss, and I've been trying to solve this since yesterday. I very much appreciate any assistance provided.

4 comments

0

You don't need to do tostring. When you do "Kills: "..value it already concatenates the string and the value to match into text.

0

This doesn't seem to solve my problem, but I appreciate in nonetheless.

0

have you gotten any errors? looking at this, it doesn't seem like there's anything wrong with it besides the tostring stuff.

0

There haven't been any errors. It's very peculiar.

1 answer

I'm not sure what caused the issue, but I worked around it. The way my system was set up was so a RemoteEvent would be fired every time the player's kill or tries value was altered (they were being stored in ServerStorage.) Instead, I stored copies of the player's stats in ReplicatedStorage. The ReplicatedStorage stats would be changed based on the ServerStorage ones, and my textlabel script would be activated every time the ReplicatedStorage stats were changed. My tries script now looks like this, and the other one is basically the same thing:

local message
message = "Chances: ".. game.ReplicatedStorage.PlayerTries:WaitForChild("Tries-".. game.Players.LocalPlayer.Name).Value
script.Parent:WaitForChild("TextLabel").Text = message
game.ReplicatedStorage.PlayerTries:WaitForChild("Tries-".. game.Players.LocalPlayer.Name).Changed:Connect(function()
	message = "Chances: ".. game.ReplicatedStorage.PlayerTries["Tries-".. game.Players.LocalPlayer.Name].Value
	script.Parent.TextLabel.Text = message
	print(script.Parent.TextLabel.Text)
end)

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