Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm using string.sub, but my output says "Invalid Argument #1 to "sub". What do I do?

Asked by 3 years ago
Edited 3 years ago

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.

0
I checked that already. I also tried gsub with numbers but It still doesn't work... Crazydave601 0 — 3y

1 answer

Log in to vote
2
Answered by 3 years ago

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!

0
Also added the explanation :) yuni_Boy1234 320 — 3y
0
Please it if helps mark it as the answer so other people know about it! yuni_Boy1234 320 — 3y
0
"Attempt to index nil with name" Crazydave601 0 — 3y
0
Can you tell the object positions please? yuni_Boy1234 320 — 3y
View all comments (4 more)
0
Here, team is the model? BestCreativeBoy 1395 — 3y
0
@yuni_Boy1234 if you mean the spawn location positions then the start is at 23.805, 1.5, 32.005 and the next checkpoint is at 27.76, 1.5, -43.38 Crazydave601 0 — 3y
0
@BestCreativeBoy Idk Crazydave601 0 — 3y
0
i mean the positions in the explorer yuni_Boy1234 320 — 3y
Ad

Answer this question