I'm using the twitch api to pull information about a channel. When I put in a valid channel it works, but after I put in a non-valid channel, it stops working. Any ideas why and how to fix it?
function handle(err)
errortext = 'ERROR: ' .. err:gsub("(.-:)","")
return errortext
end
function pcallgetasync(person)
getasync = game:GetService('HttpService'):GetAsync('https://api.twitch.tv/kraken/channels/' .. person, true)
return getasync
end
game.Players.PlayerAdded:connect(function(player)
player.PlayerGui:WaitForChild('ScreenGui').Frame.SearchBox.Search.Changed:connect(function()
person = player.PlayerGui.ScreenGui.Frame.SearchBox.Text
if player.PlayerGui:WaitForChild('ScreenGui').Frame.SearchBox.Search.Value == true then
local httpservice = game:GetService('HttpService')
player.PlayerGui.ScreenGui.Frame.SearchBox.Changed:connect(function()
person = player.PlayerGui.ScreenGui.Frame.SearchBox.Text
end)
if pcall (function() pcallgetasync(person) end) then
afollowers = string.find(getasync, '"followers":')
endthing = string.find(getasync, ',"_links"')
followers = string.sub(getasync, afollowers + 12, endthing - 1)
player.PlayerGui.ScreenGui.Frame.Followers.Text = 'Followers: ' .. followers
player.PlayerGui.ScreenGui.Frame.SearchBox.Search.Value = false
else
print(xpcall(pcallgetasync, handle))
--errortext = tostring(xpcall(pcallgetasync, handle))
a = require(game.Workspace.ErrorScript)
a(player.Name, errortext)
end
end
end)
end)

2 comments
Doesn't the pcall prevent that though?
No. The error is occuring on line 24, which is not in a function called by
pcall. (pcallis also heavy handed to fix this so that shouldn't be what you jump to solve it - just use the condition)