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

How do I make it so when I click a TextButton it changes a TextLabel?

I want to have it so when I press a button a TextLabel changes, this is the code I've came up with but it doesn't work.

local player = game.Players.LocalPlayer
local text = player.PlayerGui.GunPick.Screen.LoadoutInfo.ChangeableInfo.Primary.Text
local button = script.Parent

button.MouseButton1Click:Connect(function()
	text =  "Martini Henry"
end)


It doesn't give out any output errors or Script Analysis errors.

1 comment

0

This is put in a LocalScript inside the button.

1 answer

###You're misunderstanding variable assignment and property allocation.

This is a common mistake in the early stages of learning to program with game engines. In ROBLOX, you cannot make pointers to an Instance's property. When you reference the .Text value, the compiler in this context will be storing the said value in your variable "text".

To resolve your problem, only reference .Text when you intend to change this property:

local Player = game.Players.LocalPlayer

local TextLabel = player.PlayerGui.GunPick.Screen.LoadoutInfo.ChangeableInfo.Primary
local Button = script.Parent


Button.MouseButton1Click:Connect(function()
	---------------
	TextLabel.Text =  "Martini Henry"
end)


1 comment

0

I've changed it to that and yet it still doesn't work, with no errors in the output or SA errors, i've also fixed the mistake where you forgot to capitalize the 'P' in the variable player on line 3 and still didn't work.

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