generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: A more efficient way of doing this?

Previous Thread :: Next Thread 
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
04 Apr 2016 06:33 PM
I have FilteringEnabled set to true and I'm trying to get about 10 buy buttons to work.
Do I have to communicate to the buttons one-by-one, as follows, or is there a more effect way?

local Item1 = game.Workspace.Gamepass1.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()

--Gamepass 1
local ID = 13462354

--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ID)
end)


local Item1 = game.Workspace.Gamepass2.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()

--Gamepass 2
local ID = 13465236

--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ID)
end)


local Item1 = game.Workspace.Gamepass3.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()

--Gamepass 1
local ID = 214523624

--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ID)
end)

..and so on.

Any help or advise would be greatly appreciated.
Report Abuse
xlaser23 is not online. xlaser23
Joined: 10 Dec 2011
Total Posts: 20341
04 Apr 2016 06:36 PM
Table the ids
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
04 Apr 2016 06:44 PM
for loops exist for a reason

ids = {13462354,13465236,214523624}
for i=1,#ids do

workspace["Gamepass"..tostring(i)].SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()
--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ids[i])
end)
end
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 12:27 PM
@falsidge

Thanks. I didn't know you could join "Gampass" and testing(i) like that, although it's pretty cool.

Would it be possible to look for the buttons by finding a part that begins with "1", and then "2" and and so on.
For example, it'll find "1Gamepass" first because it recognises that it begins with "1", and then it searches for something that begins with "2".

Is that possible?

Any help or advise would be greatly appreciated.
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 12:42 PM
Any idea?
Report Abuse
KapKing47 is not online. KapKing47
Joined: 09 Sep 2012
Total Posts: 5522
05 Apr 2016 12:53 PM
ids = {
Gamepass1 = 13462354;
Gamepass2 = 13465236;
Gamepass3 = 214523624;
}

local urPass = ids[workspace.CertainObjectWithNameThatIs"Gamepass"AndANumberAtTheEnd]

"My Life is going Good... but..."
Report Abuse
KapKing47 is not online. KapKing47
Joined: 09 Sep 2012
Total Posts: 5522
05 Apr 2016 12:53 PM
local urPass = ids[workspace.CertainObjectWithNameThatIs"Gamepass"AndANumberAtTheEnd.Name]

"My Life is going Good... but..."
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
05 Apr 2016 01:02 PM
don't know what you are asking

this will loop through all the ids in the table starting at 1Gamepass then goto 2Gamepass then 3Gamepass assigning each the id

the other starts at Gamepass1


ids = {13462354,13465236,214523624}
for i=1,#ids do
workspace[i.."Gamepass"].SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()
--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ids[i])
end)
end


Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 01:23 PM
I'll give an example to that you know what I'm asking.

Let's say you have 20 gamepass Models, each with a different name, RedGamepass, BlueGamepass, YellowGamepass, etc.
You don't want to change their name completely because this would interfere with other Scripts which would take a long time to amend in full.

Instead, however, you can add a number to the start of the name. 1RedGamepass, 2BlueGamepass, and so on.

How can you make it so that the loop searches for the Model named that has a name beginning with "1", regardless of what the rest of it is called?

I think someone told me string.sub could be used for this, but I can't remember how.

Do you know what I mean?
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
05 Apr 2016 01:35 PM
oh you will just do some regex matching
haven't tested it this so


ids = {13462354,13465236,214523624}
for i,v in pairs(workspace:GetChildren())
a = string.gmatch(v.Name,"([0-9]*).*Gamepass")()
if a ~=""then
v.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()
--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ids[a])
end)
end
end
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
05 Apr 2016 01:38 PM
forgot to convert a to a number when prompting for purchase

ids = {13462354,13465236,214523624}
for i,v in pairs(workspace:GetChildren())
a = string.gmatch(v.Name,"([0-9]*).*Gamepass")()
if a ~=""then
v.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()
--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ids[tonumber(a)])
end)
end
end
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 02:04 PM
Thanks, falsidge.

I'm just trying to understand how it works right now.
I'm not sure whether you misinterpreted what I was saying.
I don't want to use the word "gamepass" at all in the code. I just want to check "if the first character of the Name is 1, do this", "if the first character of the Name is 2, do this", and so on. This is because some of the Models are called 1BlueGamepass, 2YellowGamepass, 3BigHouse, etc.

Maybe the code does this, I'm not sure?
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
05 Apr 2016 02:13 PM
the string.gmatch(v.Name,"([0-9]*).*Gamepass")() will match anything with a name
that has a number in the beginning and the word "Gamepass" in the end and capture the number

1234dasofhsdoGamepass will match and will capture the number 1234
dfdGamepass will not match
1BlueGamepass will match and capture the 1
although if you just want numbers you can do this

ids = {13462354,13465236,214523624}
for i,v in pairs(workspace:GetChildren())
a = tonumber(string.sub(v.Name,1,1))
if a then
v.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()
--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ids[a])
end)
end
end
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 02:20 PM
@falside

Thanks.
How would you make it work with double-digits?
10Gamepass, 15Gamepass, etc.


Would it go something like this?:

if string.sub(v.Name,1,2):IsA("Number") then --I know this part is definitely incorrect
a = tonumber(string.sub(v.Name,1,2))
end
Report Abuse
falsidge is not online. falsidge
Joined: 16 Jul 2013
Total Posts: 456
05 Apr 2016 02:24 PM
i would do it this way since gmatch will match all the numbers in the beginning and its a little simpler
I removed the Gamepass part so it will match anything starting with a number

ids = {13462354,13465236,214523624}
for i,v in pairs(workspace:GetChildren())
a = string.gmatch(v.Name,"([0-9]*).*")()
if a ~=""then
v.SurfaceGui.Frame.BuyButton.MouseButton1Click:connect(function()
--Promopt the purchase
game:GetService("MarketplaceService"):PromptPurchase(Player, ids[tonumber(a)])
end)
end
end
Report Abuse
earthyreuben is not online. earthyreuben
Joined: 17 Jan 2010
Total Posts: 669
05 Apr 2016 03:12 PM
Here's what I would do.

In server script service, I would create a script to handle purchases. The script will contain a function connected to a BindableFunction inside the ServerStorage (for obvious reasons). The function will accept the appropriate parameters and handle the purchase.

Then I would put a script inside of the button with a click detector and set it up so that it would Invoke the BinableFunction with the appropriate parameters.

IF I WANTED the buttons to be GUIs. I would use a local script to create them, and set them up to a RemoteFunction with the same script above (adjust for remote function). You can send the ID without worry because it won't effect the price.

I would use Bindable and Remote Functions so that I could return some data if I ever felt the need to. But I wouldn't trust the client for figuring if the purchase was valid or not, but I would trust it to display it the server's answer.
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 05:10 PM
@ falsidge

Thanks. I gave it a try.
Is it possible to make it so that the first "match" is 1, next is 2, next is 3, and so on?
At the moment, when I say print(v.Name), everything is done out of order, and for the purpose of what I'm doing I need these to be iterated in order.

I found the code the other scripter showed me. Here it is:

if v.Name:sub(1,1) == tostring(Count) or v.Name:sub(1,2) == tostring(Count) then

I've been trying to get this working in place of a = string....etc. , and it works, but not for 10Gamepass and 11BlueBrick because of the second digits.

Anyone have any help or advise on this?
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
05 Apr 2016 05:46 PM
Any ideas?
Report Abuse
Craftero is not online. Craftero
Joined: 24 Jun 2011
Total Posts: 1451
06 Apr 2016 08:02 AM
Anyone?
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image