Back

Televoting API documentation


Using the api


To use the api you simply just need to require the module located in the main televoting folder

local api = require(workspace.Televoting.API)

api:GetResults()


You can use api:GetResults() to get the full results. The returned results will be sorted by points.

local results = api:GetResults()
print(results)

Can return for example:
{
    {name = "Option 1", points = 5},
    {name = "Option 2", points = 2}
}

api:GetPointsFor(name)


You can use api:GetResults() to get the amount of points a specific voting option got.

local points = api:GetPointsFor("Option 2")
print(points)

Can return for example:
10

api:GetVotes(returnUsernames)


You can use api:GetVotes() to get the all votes sent by players. The optional returnUsernames parameter can be set to true if you want the votes to also return the usernames and not only user ids.

local votes = api:GetVotes(true)
print(votes)

Can return for example:
{
    {userid = 147274250,
    username = "gabys2005",
    votes = {"Option 1", "Option 3"}}
}

api:GetVotesFor(name, returnUsernames)


You can use api:GetVotesFor() to get the people that voted for this option. The optional returnUsernames parameter can be set to true to make the function return usernames instead of user ids.

local voted = api:GetVotesFor("Option 2")
print(voted)

Can return for example:
- when the returnUsernames parameter is set to true:
{"gabys2005", "builderman"}

- when the returnUsernames parameter is set to false:
{147274250, 156}

api:GetResultsString()


You can use api:GetVotesFor() to get the string that shows up when you click the Generate button

local resultsString = api:GetResultsString()
print(resultsString)

Can return for example:
[["Option 1","Option 2","Option 3"],["gabys2005",2,3]]