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 detect if the value in "NumberValue" Changes, if so, the text changes its text?

I making a calculator in roblox to practice my coding skills, but there seem to be a promblem

local Mainframe = script.Parent.Parent

local Value = Mainframe.GivenValue.Value

if Value == 0 then
	script.Parent.Text = "+"
else
	script.Parent.Text = "X"
end

local function onChanged(value)
	if Value == 0 then
		script.Parent.Text = "+"
	else
		script.Parent.Text = "X"
	end
end

Mainframe.GivenValue.Changed:Connect(onChanged)

the script parent is the "Text" , if i change the value in the playerGui, the text isnt changing, the text parent is the "Mainframe" and a mainframe has a numbervalue children name "GivenValue" all i need is when the givenvalue changes its value to 0, the text became "+" and when it changes to 1 or so on, the text became "X" that represent multiply, but there seem to be a promblem, if you help, i really appreciate it!

1 answer

Ok, lets try it!

First Step : We need to know where is our frame and our Text and our value. So we can create variables or tables.

Second Step : We need to know how to acces to them, so we can interect with them. Lets try something...

--> Locals <--

local frame = game.StarterGui.ScreenGui.Frame
local text = script.Parent --> This script is on the textLabel
local value = game.StarterGui.ScreenGui.Values.NumberValue

That's how we acces to the text, frame and the value. So now lets fix your code and make it more simple.

Third Step : Enjoy coding! You always have to enjoy what are you doing! Play some music while you script or even play a game before to be relaxed!

Lets get into the code!

--> Locals <--

local frame = game.StarterGui.ScreenGui.Frame
local text = script.Parent --> This script is on the textLabel
local value = game.StarterGui.ScreenGui.Values.NumberValue

--> Code <--

value.Changed:Connect(function()
	text.Text = value.Value
end)

See? You acces to the Text propertie of the textlabel and you change it to the value of the NumberValue. So when the Value detects a change then the Text will be the Value of NumberValue.

I hope my answer already solve your question. If it like that, please accept my answer. So I can know I helped you and it works!

Keep Scripting!

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