I'm trying to make a "Skip Stage" in my Obby, but my output says
"invalid argument #1 to 'sub' (string expected, got Instance)"
The code:
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) --The Service |
02 | local Players = game:GetService( "Players" ) --More Services |
03 |
04 | local productID = 1083524533 --Product ID |
05 |
06 | local function promptPurchase() --The function |
07 | local player = Players.LocalPlayer --The Player |
08 | MarketplaceService:PromptProductPurchase(player, productID) --Prompt it |
09 | MarketplaceService.PromptProductPurchaseFinished:connect( function () --When it's done |
10 | local stage = script.Parent.Parent.Parent.Parent.Parent.Team --The Team(From Alvin_Blox) |
11 | print (string.sub(stage, 6 , 7 )) --this doesn't work |
12 | end ) --end |
13 | end --end |
14 |
15 | script.Parent.MouseButton 1 Click:Connect(promptPurchase) --Connect it |
I got the script from the Developer Hub, The PromptProductPurchaseFinished from the Developer Forum, the Teams Stuff from Alvin_Blox, and the string.sub from Scripting Helpers.
Edit: I'm just testing it but the real problem is so it will teleport a player to the next spawn location's position.
The string.sub()
on its first parameter it needs a string value,The thing you inserted is a model,models are instances
01 | local MarketplaceService = game:GetService( "MarketplaceService" ) --The Service |
02 | local Players = game:GetService( "Players" ) --More Services |
03 |
04 | local productID = 1083524533 --Product ID |
05 |
06 | local function promptPurchase() --The function |
07 | local player = Players.LocalPlayer --The Player |
08 | MarketplaceService:PromptProductPurchase(player, productID) --Prompt it |
09 | MarketplaceService.PromptProductPurchaseFinished:connect( function () --When it's done |
10 | local stage = script.Parent.Parent.Parent.Parent.Parent.Team --The Team(From Alvin_Blox) |
11 | print (string.sub(stage.Name, 6 , 7 )) |
12 | end ) --end |
13 | end --end |
14 |
15 | script.Parent.MouseButton 1 Click:Connect(promptPurchase) --Connect it |
The second parameter of it,it tells in where character to start
1 | string.sub( "MyString" , 3 , 7 ) |
m(1)y(2)s(3) It means that the string.sub will start in the "S" character and it will be "String"
And the last parameter that is optional,it tells where to stop,in this case it is a seven it will be: "Strin"
The string.sub,is basically a string cutter.
Hope it helps!