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

How do I make an ImageLabel on a ScreenGui change?

Asked by 4 years ago
Edited 4 years ago

I know it's gonna be something super obvious that I just didn't figure out 'cause I'm stupid, but for the life of me I can't figure it out. I can set an image when I'm in the editor, I'm changing the gui in the PlayerGui folder, and I just can't get it to work. This is my code:

frame = game.Players.LocalPlayer.PlayerGui.dialog.all
main = frame.main
face = frame.face

op1 = frame.op1
op2 = frame.op2
op3 = frame.op3

s = "rbxassetid://4620142775"
n = "rbxassetid://4620142584"
m = "rbxassetid://4620142395"
h = "rbxassetid://4620142159"

script.parent.op1.MouseButton1Click:Connect(function()
    face.Image = h
    main.Text = "working"
end)

It's a local script, I'm new to scripting, and I'm trying to make my own dialog thing. The main text changes and works like it's supposed to, it's just the image acting up. Thank you to everyone who responds.

EDIT: Also, if you have any tips for making scripts better, like not making so many of those shortened things, please let me know.

0
What is this supposed to do? Rinextel 291 — 4y
0
i'm looking into it right now. give me a few minutes. is the script suppsed to cycle thru the faces each time you click? if so, is it supposed to change the face once when you click, or show every face when you click once royaltoe 5144 — 4y
0
It's supposed to be a dialog thing, and when the player clicks on an answer the face changes (I have neutral, happy, sad, mad) and I can change the face by just saying something like "face.Image = h" for happy. I'm new to scripting and trying to make my own stuff to get better... Take that as you will. LiquidGaming 33 — 4y
0
Sure thing. I'll do a write up in a sec royaltoe 5144 — 4y
0
Thanks man. :) LiquidGaming 33 — 4y

1 answer

Log in to vote
0
Answered by
royaltoe 5144 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

I think you were using the link for the asset instead of the texture link.. If you put just the numbers from one of the links "rbxassetid://SOME NUMBERS HERE" into the imagebutton's image property, then roblox will convert the assetid to an image link that you can use in your scripts.

Here's a video showing how to do that: https://streamable.com/0adok

Anyway, I did that for all four of your faces, and put them into a table:

local faces = {
    sad = "http://www.roblox.com/asset/?id=4620142770",
    neutral = "http://www.roblox.com/asset/?id=4620142572",
    mad = "http://www.roblox.com/asset/?id=4620142387",
    happy = "http://www.roblox.com/asset/?id=4620142149",
}

Since I put the links in a table, you can now access an image by saying faces.sad or faces.happy etc

You don't have to have them in a table. You can have them as normal variables like you did in your question, but having them in a table allows us to loop through the faces.

It was good that you named your variables, but having them as actual words instead of one letter variables helps you know what things are like in the example above.


To test that all the faces work, I looped through them when the player clicked the button:

--this is a table containing all your reaction images
--you can access an image by saying faces.sad, faces.neutral, etc.
local faces = {
    sad = "http://www.roblox.com/asset/?id=4620142770",
    neutral = "http://www.roblox.com/asset/?id=4620142572",
    mad = "http://www.roblox.com/asset/?id=4620142387",
    happy = "http://www.roblox.com/asset/?id=4620142149",
}

--this is your image button to click
--i have this script directly inside my gui. 
--change this to be the location of your image button. 
local imageButton = script.Parent.ImageButton 

--function that runs when your image button is clicked
imageButton.MouseButton1Click:Connect(function()

    --this loop displays all the faces inside our faces table
    for expression, image in pairs(faces)do
        imageButton.Image = image
        wait(.5)
    end
end)

if you wanted to make the image be the happy face when you click it you can do the following:

--this is a table containing all your reaction images
--you can access an image by saying faces.sad, faces.neutral, etc.
local faces = {
    sad = "http://www.roblox.com/asset/?id=4620142770",
    neutral = "http://www.roblox.com/asset/?id=4620142572",
    mad = "http://www.roblox.com/asset/?id=4620142387",
    happy = "http://www.roblox.com/asset/?id=4620142149",
}

--this is your image button to click
--i have this script directly inside my gui. 
--change this to be the location of your image button. 
local imageButton = script.Parent.ImageButton 

--function that runs when your image button is clicked
imageButton.MouseButton1Click:Connect(function()
    imageButton.Image = faces.sad
end)

let me know if you have any more questions

0
Thank you so much, it was super informative, and the cherry on top was putting the faces in for me. You're the best, thank you so much! LiquidGaming 33 — 4y
0
:) royaltoe 5144 — 4y
Ad

Answer this question