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:
local MarketplaceService = game:GetService("MarketplaceService")--The Service local Players = game:GetService("Players")--More Services local productID = 1083524533--Product ID local function promptPurchase()--The function local player = Players.LocalPlayer--The Player MarketplaceService:PromptProductPurchase(player, productID)--Prompt it MarketplaceService.PromptProductPurchaseFinished:connect(function()--When it's done local stage = script.Parent.Parent.Parent.Parent.Parent.Team--The Team(From Alvin_Blox) print(string.sub(stage,6,7))--this doesn't work end)--end end--end script.Parent.MouseButton1Click: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
local MarketplaceService = game:GetService("MarketplaceService")--The Service local Players = game:GetService("Players")--More Services local productID = 1083524533--Product ID local function promptPurchase()--The function local player = Players.LocalPlayer--The Player MarketplaceService:PromptProductPurchase(player, productID)--Prompt it MarketplaceService.PromptProductPurchaseFinished:connect(function()--When it's done local stage = script.Parent.Parent.Parent.Parent.Parent.Team--The Team(From Alvin_Blox) print(string.sub(stage.Name,6,7)) end)--end end--end script.Parent.MouseButton1Click:Connect(promptPurchase)--Connect it
The second parameter of it,it tells in where character to start
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!