I’m trying to make the script work so if it does not detect a trello card with the title of the player’s UserId, it will create a new one.
I have it down so it can detect if a card does exist, however I do not have much of an idea how to check if a card does not exist.
some values in the script have been removed.
local HttpService = game:GetService("HttpService")
local url = "trello key removed for public, exists in real script"
local TrelloAPI = require(game.ServerScriptService:WaitForChild("TrelloAPI"))
print("Loading successful.")
function getPlayerCheck(username)
local req = HttpService:GetAsync(url)
local jsontable = HttpService:JSONDecode(req)
for _, card in pairs(jsontable) do
if string.lower(card.name) == string.lower(username) then
print("Player found.")
elseif not string.lower(card.name) == string.lower(username) then --this is the area I need help with.
print("Player not found. Creating new miles account.")
TrelloAPI:AddCard(string.lower(username),[[0]],[[list id, removed for public]])
end
end
end
game.Players.PlayerAdded:Connect(function(Player)
getPlayerCheck(Player.UserId)
end)
I think that you already have it solved? Your checking if they have a card and then if they don’t have one, elseif not string.lower(card.name) == string.lower(username) then (I may be completely wrong.)
You’d have to redo the way you setup the code anyways, because itll keep creating unnecessary cards that you dont want with the way you have written now.
This should be a bit better
local url = "trello key removed for public, exists in real script"
local TrelloAPI = require(game.ServerScriptService:WaitForChild("TrelloAPI"))
print("Loading successful.")
function checkTrelloForCard(username)
local ok = false
local req = HttpService:GetAsync(url)
if req == nil then return ok end
local jsontable = HttpService:JSONDecode(req)
if jsontable == nil then return ok end
if username == nil then return ok end
for _, card in pairs(jsontable) do
if string.lower(card.name) ~= string.lower(username) then continue end
ok = true
end
return ok
end
function getPlayerCheck(username)
local req = HttpService:GetAsync(url)
local jsontable = HttpService:JSONDecode(req)
if checkTrelloForCard(username) == true then
print("Player found.")
else
print("Player not found. Creating new miles account.")
TrelloAPI:AddCard(string.lower(username),[[0]],[[list id, removed for public]])
end
end
game.Players.PlayerAdded:Connect(function(Player)
getPlayerCheck(Player.UserId)
end)
If you don’t want to subcribe to an actual datastore service, use Roblox’s. Trello is productivity software… You might get blacklisted from their API. This is so wierd.