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

How to get a function on PlayerAdded when there is a long amount of function in front of it?

Asked by
uhTeddy 101
5 years ago

I am working on a script that has a lot of functions above the .PlayerAdded function but, because of this, the function isn't registering because the player is already added at this point. I cannot move it up because all the variables that I am saving are above the function. This is my script for example:

local main = {}

script:WaitForChild("MainEvents").Parent = game:GetService("ReplicatedStorage")

function main(settings)
    script:WaitForChild("MainUI").Parent = game:GetService("StarterGui")
    print("Started")
    --------------- Start of Trello -----------------

    local token = settings.TrelloToken -- The Value of the token
    local key = settings.TrelloKey -- The Value of the key
    local newkey = Instance.new("StringValue") -- Creating a new value
    newkey.Name = "Key"
    newkey.Value = key
    newkey.Parent = script:WaitForChild("MainAPI") -- Parenting
    local newtoken = Instance.new("StringValue") -- Creating a new value
    newtoken.Name = "Token"
    newtoken.Value = token
    newtoken.Parent = script:WaitForChild("MainAPI") -- Parenting

    local SendSettings = game:GetService("ReplicatedStorage"):WaitForChild("MainEvents"):WaitForChild("SendSettings")
    local ServerAPI = script:WaitForChild("ServerAPI")
    ServerAPI.Parent = game:GetService("ServerScriptService")

    local ap = require(ServerAPI)
    local BoardID = ap:GetBoardID("simpleTech")
    local Application = ap:GetListID("Application", BoardID)
    local Blacklist = ap:GetListID("Blacklist", BoardID)


    function main:sendinfo(plr)
        local found = false
        for i,v in ipairs(ap:GetCardsInList(Application)) do
            if v.name == tostring(game.PlaceId) then
                found = true
            end
        end
        if found then
            SendSettings:FireClient(plr, settings, {true, ""})
        else
            SendSettings:FireClient(plr, settings, {false, "Whoops! This application center isn't registered yet. Please make sure its registered to use!"})
        end
    end
end

return main

Its a module script getting required

Answer this question