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

Why won't my text and image changer work?

I'm trying to make a selection GUI that will change an image and text at the same time, but nothing happens when the button is clicked.

local bu = script.Parent
local value = 1
local text = script.Parent.Text
local phone = script.Parent.Parent.PhoneTemplate.Image

bu.MouseButton1Down:connect(function()
	value = 1 + 1
	if value == 3 then
		value = 1
	end
end)

value.Changed:connect(function() 
if value == 1 then
	text = "Button Style (1/3)"
	phone = "rbxassetid://1995879731"
	if value == 2 then
		text = "Button Style (2/3)"
		phone = "rbxassetid://1996485774"
		if	value == 3 then
			text = "Button Style (3/3)"
			phone = "rbxassetid://1996484171"
			end
	end
end
end)

Thanks if you can help!

3 comments

0

Do you mean value = value+1? Because otherwise value will always be 2

0

I changed it to value = value + 1

0

You have two problems

2 answers

✓ Accepted answer

This is because you tried to use the Changed event on a variable, and on lines 3-4, tried to set the text with a variable. It also errors since you use deprecated code. Connect not connect.

local texts = {
    "Button Style (1/3)", 
    "Button Style (2/3)",
    "Button Style (3/3)"
}

local images = {
    "rbxassetid://1995879731",
    "rbxassetid://1996485774",
    "rbxassetid://1996484171"
}
    
local value = script.Parent.Clicks -- change from number to object
local text = script.Parent --remove the .Text
local phone = script.Parent.Parent.PhoneTemplate -- remove the .Image

text.MouseButton1Click:Connect(function() --:Connect not :connect
    -- use mousebutton1click instead, this is more accurate than button1down.

    value.Value = value.Value + 1 -- intvalue
end) 

value.Changed:Connect(function(new)
    if new == 1 then
        text.Text = texts[1]
        phone.Image = images[1]
    elseif new == 2 then
        text.Text = texts[2]
        phone.Image = images[2]
    elseif new == 3 then
        text.Text = texts[3]
        phone.Image = images[3]
    elseif new > 3 then
        text.Text = texts[1]
        phone.Image = images[1]
        value.Value = 1
    end
end)

16 comments

0

I don't get what you mean by I set it to the properties value.

0

Yes, as in you set your 'text' variable to just 'script.Parent.Text'. It doesn’t set the variable to the text property itself, but the current text at the time. So for example if the current text was "Hello" local text = script.Parent.Text would be the same as local text = "Hello"

0

Same thing with the phone variable. Remove the .Image

0

Is the rbxassetid part wrong? Because even when fixing it from the properties value nothing happens.

0

Made a new edit. Try it now. Make sure the value variable in my line 1 is an IntValue.

0

The text does change, but I can't find where to add "if value == 3 then value = 1" anywhere, also the image disappears.

0

It’s all under the Changed event. No worry about if value == blah

0

I'm trying to have it reset when it reaches 3

0

Editing right now.

0

also do you know the image disappears? I'm not good using "rbxassetid"

0

It shouldn’t disappear with rbxassetid. You’re correct on that end.

0

Also i’m done editing.

0

after it resets it doesnt go up again

0

Added one more thing.

0

The loop works, thanks! The image disappears though, it normally happens so I'm gonna need to figure that out

0

No problem! I’m here to help others.

Changed is an event made for properties, it isn't used on variables to my knowledge.

An easy solution would just be to change your Changed event to a function like so:

local bu = script.Parent
local value = 1
local text = script.Parent.Text
local phone = script.Parent.Parent.PhoneTemplate.Image

local function changedValue()
if value == 1 then
    text = "Button Style (1/3)"
    phone = "rbxassetid://1995879731"
    if value == 2 then
        text = "Button Style (2/3)"
        phone = "rbxassetid://1996485774"
        if  value == 3 then
            text = "Button Style (3/3)"
            phone = "rbxassetid://1996484171"
            end
    end
end
end)

bu.MouseButton1Down:connect(function()
    value = value + 1
    if value == 3 then
        value = 1
    end
    changedValue()
end)

3 comments

0

You should replace value = 1 + 1 with value = value + 1.

0

I just copied what he wrote but ill change it, i'm sure thats what he meant

0

I replaced the value = 1 + 1 to value = value + 1, but it still won't work even with incapaz's edits too.

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