Yea, it is definitely possible to do this. First, you would need to create a table. To do this, we simply need to define one, then enter in the id's of our Images. Something like this would work:
Table={"9999999","11111111","0000001"}
So now that we have the table assigned, we need to randomly select from the table. To do this, we'll use , math.random to pick a number to choose from the table:
Picked=Table[math.random(1,#Table)]
Now that we have these both set up, we can go ahead and enter them into the script. So the finished product should look something like this:
Table={"9999999","11111111","0000001"}
function onButtonClick()
Picked=Table[math.random(1,#Table)]
script.Parent.Parent.Parent.Parent.NewItemsFrame.Card1.Image ="rbxassetid://"..Picked
end
script.Parent.MouseButton1Click:connect(onButtonClick)
Now the code should work! Anyways, hope I helped you out, and as always, if you still have a problem or question, feel free to leave a comment below :P
UPDATE
This should work now:
Table1={"261746216","261746507","261746654","261747019"}
function onButtonClick1()
local Picked=Table1[math.random(1,#Table1)]
script.Parent.Parent.Parent.Parent.NewItemsFrame.Card1.Image ="rbxassetid://"..Picked
script.Parent.Parent.Parent.Parent.NewItemsFrame.Visible = true
script.Parent.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onButtonClick1)
Table2={"261752121","261751827","261751592","261751281","261751020","261750728","261750417","261750092","261749867","261749620","261749411","261749156","261748731","261748439","261748193","261747943","261747788","261747543","261747333","261747185"}
function onButtonClick2()
local Picked=Table2[math.random(1,#Table2)]
script.Parent.Parent.Parent.Parent.NewItemsFrame.Card2.Image ="rbxassetid://"..Picked
script.Parent.Parent.Parent.Parent.NewItemsFrame.Visible = true
script.Parent.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onButtonClick2)
Table3={"261752121","261751827","261751592","261751281","261751020","261750728","261750417","261750092","261749867","261749620","261749411","261749156","261748731","261748439","261748193","261747943","261747788","261747543","261747333","261747185"}
function onButtonClick3()
local Picked=Table3[math.random(1,#Table3)]
script.Parent.Parent.Parent.Parent.NewItemsFrame.Card3.Image ="rbxassetid://"..Picked
script.Parent.Parent.Parent.Parent.NewItemsFrame.Visible = true
script.Parent.Parent.Parent.Visible = false
end
script.Parent.MouseButton1Click:connect(onButtonClick3)
It should work now. I just made sure that the variables were all assigned different names so that the script didn't mix them all up. If there's any more problems, leave another comment and i'll see what I can do :P
13 comments
so the numbers you have at the top (9999999, etc.) are the ID's? And this is the whole script?
Yup. The actual Id's can be found at the top of the page where the image is. They should be just a bunch of numbers at the end of the url. Replace the ones I put with those.
In the same script, I want it to also change the image of Card2 and Card3, would I just copy and paste the same code and tweek it a little, while all still in the same script?
No, that is the decal not the image.
You could if you wanted to, yea. It'd work if you did it correctly.
Thanks! I'm going to test it :P
No prob. Hope I helped. If you run into any problems, let me know
There is a problem, Card2 and Card3 are working fine, but Card1 isn't showing up. In an answer, I'll post the script I have.
Exactly, That is the problem with your script
Dude...
Not working :/
The frame with the images won't even open now, I can click the button, but nothing happens.
Message me on Roblox