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

How can I generate a random word?

Asked by 5 years ago
Edited 5 years ago

How can I generate a random word?
I was thinking of doing a ‘post request’ from http://watchout4snakes.com/wo4snakes/Random/RandomWord
but im not sure how to.

0
i never knew you can use that for random generation cool actually starmaq 1290 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago
Edited 5 years ago

nvm, This works:

01local HttpService = game:GetService("HttpService")
02 
03local function randomword()
04 
05local response = HttpService:RequestAsync(
06 
07{
08 
09Url = "http://watchout4snakes.com/wo4snakes/Random/RandomWord", -- This website helps debug HTTP requests
10 
11Method = "POST",
12 
13Headers = {
14 
15["Content-Type"] = "application/json"
16 
17},
18 
19Body = HttpService:JSONEncode({hello = "world"})
20 
21}
22 
23)
24 
25-- Inspect the response table
26 
27if response.Success then
28 
29return(response.Body)
30 
31else
32 
33print("The request failed:", response.StatusCode, response.StatusMessage)
34 
35end
36 
37end
38 
39local success, message = pcall(randomword)
40 
41if not success then
42 
43print("Http Request failed:", message)
44 
45end
46 
47 
48 
49 
50print(randomword())
Ad

Answer this question