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:
local PackPlayers = {"Nytroz", "Legendowski", "HypervenomPhantomz"} 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:
local PackPlayers = {"Nytroz", "Legendowski", "HypervenomPhantomz"} numOfPlayers = 4 for i=1,numOfPlayers do PackPlayers[i] = display.newImageRect("images/http://www.roblox.com/asset/?id=146289136", 200, 280) PackPlayers[i].x = math.random(0, display.contentWidth) PackPlayers[i].y = math.random(0, display.contentHeight) 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:
local PossibleImages = {146289136} local MaxImages = 4 function GetImage() return "http://www.roblox.com/asset/?id="..PossibleImages[math.random(1, #PossibleImages)] end function CreateImage(img, x) local new = Instance.new("ImageLabel") new.Image = img new.Position = UDim2.new(0.2 * x, 0, 0.5, 0) new.Size = UDim2.new(0.1, 0, 0.1, 0) new.Parent = game.Players.LocalPlayer.PlayerGui.Gui -- somewhere in PlayerGui end button.MouseButton1Down:connect(function() button.Visible = false for i = 1, MaxImages do local img = GetImage() CreateImage(img, i) end end)
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:
local image = Instance.new("ImageLabel") image.Parent = script.Parent image.Size = UDim2.new(0, 300, 0, 300) image.Image = "rbxassetid://1234" image.Position = UDim2.new(0, 300, 0, 400) -- and so on