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

Advance ScreenGui Image loader?

Asked by 6 years ago
Edited 6 years ago

First I want to start off, I can not script, but I can read script. Make any script and i can read it and understand how it works in every detail. I'm just very bad at scripting since I've only started a about 10ish days ago.

Now to my question. It is no normal ScreenGui question since i'm almost a master at gui, but my question is . . .

How can I script a, localscript? or a normal script, i think a localscript since it'll be inside of StarterGui.

How can I script a localScript and have it function something like . . .(btw like i said i cant script, but i have the idea behind the script.)

local ProfilePic = game.Player.LocalPlayer.--[[idk i just want to pull an image of them]]--

Script.Parent.MouseButton1Down:connect(function() --What I want is when I click on the TextButton or ImageButton, I want it to load the player's profile pic or image into a imagelabel-- maybe, ProfilePic.Leaderboard.--[and i want a leaderstats] . . . .

Thats the problem i'm having, idk how to pull a image of a player. i know i want, when player click textbutton, then imagelabel = player profile pic (or) player image.

Problem is i dont know how to script that. Need some help.

0
I'm confused what your question exactly is. Here's a related question about loading a player image .. https://scriptinghelpers.org/questions/7047/how-to-get-a-player-image User#18718 0 — 6y
0
When I click on a TextButton how can I make the localscript load a image of the player who click on the button into a image on the side. Btw that link doesnt help. Khornos 0 — 6y
0
I answered on your old post (https://scriptinghelpers.org/questions/51474/how-to-load-a-profile-pic-to-screen-gui) but I re-answered here, hope it helps. superhudhayfa 39 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

I answered this on your other post, I'll just and answer it again here.

I'm going to talk you through this step by step, with the final code at the end.

Okay, let's say you have a ScreenGui in StarterGui and inside of that ScreenGui, you have 3 children. A Local script, a text button and an image label. The first thing you want to do is get the "Players" service, you can do this by using this simple line of code:

local Players = game:GetService("Players")

Now that you have the player service, we need to define the player's username. There are probably easier methods, but the way I did it was like this:

local Players = game:GetService("Players")
local plrName = game.Players.LocalPlayer.Character.Name

Once you have defined the player's username, you need to make a variable for the image itself. To get a player's image, you put this into the image id:

"http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" --followed by their username.

So, using this method and the "plrName" variable we just defined, we can access the player's image.

local Players = game:GetService("Players")
local plrName = game.Players.LocalPlayer.Character.Name
local image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. plrName

Now there are only 2 more steps. The function, and the code that goes inside of the function. Fear not, it's as easy as the other code above! The function needs to be launched everytime the TextButton is clicked, so we use the MouseButton1Click method. Alternatively, you can use MouseButton1Down, where you just need to press down the mouse button, but this way they have to press down and let go of the mouse while it's on top of the button. We can do this by:

script.Parent.TextButton.MouseButton1Click:connect(function() end)

So, our code so far is:

local Players = game:GetService("Players")
local plrName = game.Players.LocalPlayer.Character.Name
local image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. plrName

script.Parent.TextButton.MouseButton1Click:connect(function() -- Change "script.Parent.TextButton" to the directory of the text button
end)

Now the final bit of code. All we need to do is get the image label's current image and set it to our new image, we do this by first accessing the image label.

script.Parent.ImageLabel

Then getting it's image.

script.Parent.ImageLabel.Image

Then change the image

script.Parent.ImageLabel.Image = image

So our final code would be:

local Players = game:GetService("Players")
local plrName = Players.LocalPlayer.Character.Name
local image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. plrName

script.Parent.TextButton.MouseButton1Click:connect(function()
    script.Parent.ImageLabel.Image = image
end)

Or, if you wanted it a bit neater:

local Players = game:GetService("Players")
local plrName = Players.LocalPlayer.Character.Name
local image = "http://www.roblox.com/Thumbs/Avatar.ashx?x=420&y=420&username=" .. plrName
local textButton = script.Parent.TextButton -- Change to directory of the textButton
local imageLabel = script.Parent.ImageLabel -- Change to directory of the image label

function onClicked()
    imageLabel.Image = image
end

textButton.MouseButton1Click:connect(onClicked)

Hope this helped, if there are any issues, please contact me. If it did help, make sure to make this as resolved.

Ad

Answer this question