# Step 1: Require necessary libraries
require 'net/http'
require 'json'
# Step 2: Define the function to get free robux
def get_free_robux(username)
# Step 3: Set the Roblox API endpoint
api_url = "https://api.roblox.com/users/get-by-username?username=#{username}"
# Step 4: Make a GET request to the API
response = Net::HTTP.get(URI(api_url))
# Step 5: Parse the JSON response
user_data = JSON.parse(response)
# Step 6: Check if the user exists
if user_data['success']
user_id = user_data['Id']
# Step 7: Set the Robux API endpoint
robux_url = "https://api.roblox.com/currency/balance?userId=#{user_id}"
# Step 8: Make a GET request to the Robux API
robux_response = Net::HTTP.get(URI(robux_url))
# Step 9: Parse the JSON response for Robux
robux_data = JSON.parse(robux_response)
# Step 10: Display the user's Robux balance
puts "#{username} has #{robux_data['robux']} Robux."
else
# Step 11: Display an error message if the user doesn't exist
puts "User #{username} not found."
end
end
# Step 12: Call the function with a username to get free Robux
get_free_robux('example_username')