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!
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)
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)