So, when the user clicks, it makes another frame visible making itself invisible while at the same time display 4 random images. I have 1 image so far (I will be making the others later): images/http://www.roblox.com/asset/?id=146289136 I have got as far as this:
1 | local PackPlayers = { "Nytroz" , "Legendowski" , "HypervenomPhantomz" } |
2 | numOfPlayers = 4 |
numOfPlayers meaning the maximum amount of images to display. Am I going about this correctly? And how would I continue? My previous code was this:
1 | local PackPlayers = { "Nytroz" , "Legendowski" , "HypervenomPhantomz" } |
2 | numOfPlayers = 4 |
3 |
4 |
5 | for i = 1 ,numOfPlayers do |
6 | PackPlayers [ i ] = display.newImageRect( "images/http://www.roblox.com/asset/?id=146289136" , 200 , 280 ) |
7 | PackPlayers [ i ] .x = math.random( 0 , display.contentWidth) |
8 | PackPlayers [ i ] .y = math.random( 0 , display.contentHeight) |
9 | end |
I found it on the internet and tried to edit the syntax to work with Roblox LUA. But of course it didn't work. So I am asking you guys here to assist me.
For starters, you are trying to use members of display. If this is all your code, display is nil, meaning it will error.
I also don't understand your code. Why are you overwriting PackPlayers?
If you just want to show random images, why would you need ImageRects? Why not show the Images themselves?
I would do this:
01 | local PossibleImages = { 146289136 } |
02 | local MaxImages = 4 |
03 |
04 | function GetImage() |
05 | return "http://www.roblox.com/asset/?id=" ..PossibleImages [ math.random( 1 , #PossibleImages) ] |
06 | end |
07 |
08 | function CreateImage(img, x) |
09 | local new = Instance.new( "ImageLabel" ) |
10 | new.Image = img |
11 | new.Position = UDim 2. new( 0.2 * x, 0 , 0.5 , 0 ) |
12 | new.Size = UDim 2. new( 0.1 , 0 , 0.1 , 0 ) |
13 | new.Parent = game.Players.LocalPlayer.PlayerGui.Gui -- somewhere in PlayerGui |
14 | end |
15 |
Well, uh, display.newImageRect
isn't even part of the ROBLOX API.
What I think you want to do is make a image on the screen. In this case, you'll want to use a ImageLabel.
Also, you're going to need to use a TextButton or ImageButton to detect those clicks.
To create an ImageLabel, just follow the standard procedure when creating objects in the ROBLOX API:
1 | local image = Instance.new( "ImageLabel" ) |
2 | image.Parent = script.Parent |
3 | image.Size = UDim 2. new( 0 , 300 , 0 , 300 ) |
4 | image.Image = "rbxassetid://1234" |
5 | image.Position = UDim 2. new( 0 , 300 , 0 , 400 ) |
6 | -- and so on |