Advertisement
AutumnMoon88683

catfact roblox script

Dec 9th, 2024
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.59 KB | None | 0 0
  1. local plr = game.Players.LocalPlayer
  2.         local TextChatService = game:GetService("TextChatService")
  3.         local ReplicatedStorage = game:GetService("ReplicatedStorage")
  4.         local isLegacyChat = TextChatService.ChatVersion == Enum.ChatVersion.LegacyChatService
  5.         function chatMessage(str)
  6.             str = tostring(str)
  7.             if not isLegacyChat then
  8.                 TextChatService.TextChannels.RBXGeneral:SendAsync(str)
  9.             else
  10.                 ReplicatedStorage.DefaultChatSystemChatEvents.SayMessageRequest:FireServer(str, "All")
  11.             end
  12.         end
  13.         -- Define the URL for cat facts
  14.         local url = "https://meowfacts.herokuapp.com/"
  15.  
  16.         -- Create an HTTP service instance
  17.         local HttpService = game:GetService("HttpService")
  18.  
  19.         -- Define the character limit for TextChat
  20.         local textChatCharacterLimit = 200
  21.  
  22.         -- Function to fetch the cat fact
  23.         local function fetchCatFact()
  24.             local validFact = false
  25.             local catFact = ""
  26.  
  27.             while not validFact do
  28.                 -- Make the GET request
  29.                 local response = game:HttpGet(url)
  30.  
  31.                 if response then
  32.                     -- Decode the JSON response
  33.                     local responseData = HttpService:JSONDecode(response)
  34.  
  35.                     -- Extract the third line of content (assuming it's a string list)
  36.                     catFact = responseData.data[3]  -- Adjust the index based on actual response structure
  37.  
  38.                     -- Check if the cat fact is within the character limit
  39.                     if #catFact <= textChatCharacterLimit then
  40.                         validFact = true
  41.                     end
  42.                 else
  43.                     warn("Failed to fetch valid cat fact")
  44.                     return
  45.                 end
  46.             end
  47.  
  48.             -- Output the valid cat fact
  49.             chatMessage(catFact)
  50.         end
  51.  
  52.         -- Fetch the cat fact
  53.         fetchCatFact()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement