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

How would I make this http command work?

Asked by 9 years ago
--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.
0
This seems to work, but your comments need to have '--', not '-' before them. TheDeadlyPanther 2460 — 9y
0
No that was just for an explanation. NotNowSkid 10 — 9y

1 answer

Log in to vote
-1
Answered by 9 years ago

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.

Ad

Answer this question