Let’s make a fancy live subscriber count in roblox studio
I can’t provide you with the plugin since roblox have crashed on me for no reason without any warning after I finished the video So this plugin only lives on this video currently. If you managed to recreate it, Please share it with me in discord!
This video covers a lot of useful stuff. like how to use HttpService with youtube API. How to handle gui’s and plugin widgets, and more…
I appreciate feedback, constructive criticism and suggestions
Unfortunately as I said my studio crashed after an hour of hardwork as you’ve seen in the video. but it’s pretty simple:
First follow my tutorial about how to get your own youtube API key.
Second try to copy the function implementation of GetChannelData(ID) from my video.
GetChannelData will return a table containing the data you need for the specified ID
local HttpService = game:GetService("HttpService")
local NumberSpinner = require(script.NumberSpinner)
local Toolbar = plugin:CreateToolbar("Youtube Channel Tracker")
local Buttons = {
ChannelSelector = Toolbar:CreateButton("Select Channel", "Select Channel", ""),
SubscribersTracker = Toolbar:CreateButton("Subscribers Tracker", "Subscribers Tracker", ""),
}
local WidgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Left,
false,
false,
400,
160,
400,
160
)
local Widgets = {
ChannelSelector = plugin:CreateDockWidgetPluginGui("ChannelSelector", WidgetInfo),
SubscribersTracker = plugin:CreateDockWidgetPluginGui("SubscribersTracker", WidgetInfo)
}
Widgets.ChannelSelector.Title = "Channel Selector"
Widgets.SubscribersTracker.Title = "Subscribers Tracker"
local GUI = script.Parent.GUI
local SubcriberCountNumberSpinner = nil
local Frames = {
ChannelSelector = GUI.ChannelSelector,
SubscribersTracker = GUI.SubscribersTracker
}
local SelectButton = Frames.ChannelSelector.Holder.SelectButton
local IDTextBox = Frames.ChannelSelector.Holder.ChannelSelector.TextBox
local config = {
key = "AIzaSyDf4rwNKscEIf5QJ9CQHp7WQlrEzFt6d7I",
API_URL = "https://www.googleapis.com/youtube/v3/channels?part=statistics&id="
}
local open = {
ChannelSelector = false,
SubscribersTracker = false
}
local function GetChannelData(ID)
local data = nil
local success, err = pcall(function()
local url = config.API_URL..ID.."&key="..config.key
local response = HttpService:GetAsync(url)
data = HttpService:JSONDecode(response)
end)
if not success then
warn("Something went wrong!")
end
return data.items[1].statistics
end
local function UpdateChannelID()
local ID = IDTextBox.Text
local ChannelData = GetChannelData(ID)
if ChannelData.hiddenSubscriberCount then
warn("The requested channel's subscibers count is hidden!")
else
local SubscriberCount = tonumber(ChannelData.subscriberCount)
SubcriberCountNumberSpinner.Value = SubscriberCount
end
end
local function InitButtons()
for ButtonName, Button in pairs(Buttons) do
Button.Click:Connect(function()
if open[ButtonName] then
Widgets[ButtonName].Enabled = false
open[ButtonName] = false
else
Widgets[ButtonName].Enabled = true
open[ButtonName] = true
end
end)
end
end
local function InitWidgets()
for WidgetName, Widget in pairs(Widgets) do
local frame = Frames[WidgetName]
frame.Parent = Widget
end
end
local function InitSubscribersTracker()
SubcriberCountNumberSpinner = NumberSpinner.new()
SubcriberCountNumberSpinner.Decimals = 0
SubcriberCountNumberSpinner.Duration = 1
SubcriberCountNumberSpinner.Parent = Frames.SubscribersTracker.Holder.SubsCount
SubcriberCountNumberSpinner.Prefix = ""
SubcriberCountNumberSpinner.Position = UDim2.fromScale(0.5, 0.5)
SubcriberCountNumberSpinner.AnchorPoint = Vector2.new(0.5, 0.5)
SubcriberCountNumberSpinner.Size = UDim2.fromScale(1, 1)
SubcriberCountNumberSpinner.TextSize = 64
end
local function Init()
InitWidgets()
InitSubscribersTracker()
InitButtons()
end
SelectButton.MouseButton1Click:Connect(UpdateChannelID)
Init()