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

How would I make this http command work?

--I've tried but this won't work.
game.Players.PlayerAdded:connect(function(player)
player.Chatted:connect(function(msg)
if msg:sub(1,2) == "h/" then -My chatted command game:GetService("HttpService"):GetAsync(msg:sub(3))-Gets any raw link when saying h/.
end
end)
end)
--What I want it to do is that whenever I type "h/" it sends the link back using the function getasync. And that means any link. That has roblox lua code in it.

2 comments

0

This seems to work, but your comments need to have '--', not '-' before them.

0

No that was just for an explanation.

1 answer

Try this:

game.Players.PlayerAdded:connect(function(player)
	player.Chatted:connect(function(msg)
		if msg:sub(0,2):match("h/") then 
			game:GetService("HttpService"):GetAsync(msg:sub(3))
		end
	end)
end)

The issue was you were selecting only 1,2 of the message to select h/. I also changed it so that it uses a more reliable function called :match(), which matches any part of a string.

The string, or any string, when using :sub, starts at 0, then ends at the total length of the string.

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