Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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.

2 comments

0

I checked that already. I also tried gsub with numbers but It still doesn't work...

1 answer

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!

8 comments

0

Also added the explanation :)

0

Please it if helps mark it as the answer so other people know about it!

0

"Attempt to index nil with name"

0

Can you tell the object positions please?

0

Here, team is the model?

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

0

@BestCreativeBoy Idk

0

i mean the positions in the explorer

This discussion is preserved as it was. New answers, comments, and votes are closed.