Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

error with my script It keeps saying string expected got nil)on line 34, can someone help?

Asked by 2 years ago

Here is the script

local HttpService = game:GetService("HttpService")

local Webhook = {}
Webhook.__index = Webhook

function Webhook.new(name, team, timeAmount)
    return setmetatable({
        playerName = name,
        playerTeam = team,
        timeTaken = timeAmount,
    }, Webhook)
end

function Webhook:Post(webhook)
    local data = {
        embeds = {
            {
                title = "**ACTIVITY LOG**",
                color = 34749,
                footer = {
                    text = "2"
                },
                fields = {
                    {
                        name = "**USERNAME**",
                        value =     string.upper(self.playerName)
                    },
                    {
                        name = "**UNIT**",
                        value =     string.upper(self.playerTeam)
                    },
                    {
                        name = "**TOTAL TIME**",
                        value =     string.upper(self.timeTaken)
                    },
                }
            }
        }
    }

    data = HttpService:JSONEncode(data)
    HttpService:PostAsync(webhook, data)
end

return Webhook

1 answer

Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

timeAmount may not be a string so you must convert it to a string.

Change line 10 to:

timeTaken = tostring(timeAmount),

if that does not work then try changing line 10 to:

timeTaken = tostring(timeAmount.Value),

If this solution works PLEASE mark this answer as accepted :)

Ad

Answer this question