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

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

Asked by 3 years ago
Edited 3 years ago

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.

0
This is put in a LocalScript inside the button. OrdinaryTeaCup 0 — 3y

1 answer

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
3 years ago

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)


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. OrdinaryTeaCup 0 — 3y
Ad

Answer this question