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

Why won't my text and image changer work?

Asked by 5 years ago

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!

0
Do you mean value = value+1? Because otherwise value will always be 2 theCJarmy7 1293 — 5y
0
I changed it to value = value + 1 CaptainAlien132 225 — 5y
0
You have two problems CDDevelopment 6 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

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)
0
I don't get what you mean by I set it to the properties value. CaptainAlien132 225 — 5y
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" User#19524 175 — 5y
0
Same thing with the phone variable. Remove the .Image User#19524 175 — 5y
0
Is the rbxassetid part wrong? Because even when fixing it from the properties value nothing happens. CaptainAlien132 225 — 5y
View all comments (12 more)
0
Made a new edit. Try it now. Make sure the value variable in my line 1 is an IntValue. User#19524 175 — 5y
0
The text does change, but I can't find where to add "if value == 3 then value = 1" anywhere, also the image disappears. CaptainAlien132 225 — 5y
0
It’s all under the Changed event. No worry about if value == blah User#19524 175 — 5y
0
I'm trying to have it reset when it reaches 3 CaptainAlien132 225 — 5y
0
Editing right now. User#19524 175 — 5y
0
also do you know the image disappears? I'm not good using "rbxassetid" CaptainAlien132 225 — 5y
0
It shouldn’t disappear with rbxassetid. You’re correct on that end. User#19524 175 — 5y
0
Also i’m done editing. User#19524 175 — 5y
0
after it resets it doesnt go up again CaptainAlien132 225 — 5y
0
Added one more thing. User#19524 175 — 5y
0
The loop works, thanks! The image disappears though, it normally happens so I'm gonna need to figure that out CaptainAlien132 225 — 5y
0
No problem! I’m here to help others. User#19524 175 — 5y
Ad
Log in to vote
0
Answered by
Vulkarin 581 Moderation Voter
5 years ago
Edited 5 years ago

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)
0
You should replace `value = 1 + 1` with `value = value + 1`. T0XN 276 — 5y
0
I just copied what he wrote but ill change it, i'm sure thats what he meant Vulkarin 581 — 5y
0
I replaced the value = 1 + 1 to value = value + 1, but it still won't work even with incapaz's edits too. CaptainAlien132 225 — 5y

Answer this question