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

How do I connect multiple function to a single event like so?

Asked by 6 years ago
Edited 6 years ago

https://i.imgur.com/wLGCbYV.png

Picture of the tool I am using, ignore anything outside of the blue squares

context: I am making a potion script using a module script in a tool. Each potion tool is given certain effects in the folder named "Effect", which has string values. The variables for the effect is found under the configuration folder, and in the folder of the respective effect's name.

This is what is in the module script named "gamescript"

ptypelist = {health = healtheffect(),strength=strengtheffect(),speed = speedeffect()} -- The functions here are from the module script. Each of these functions require two parameter, the character, and the configuration folder

    function gamescript.potiondrink(chr,effect,config) -- "chr" is Character of the player, "effect" is the folder "Effect", "config" is the configuration folder.
        local t = {} -- Container for the list of effect functions
        for i,v in pairs(effect:GetChildren()) do
            table.insert(t,1,ptypelist[v.Value])
        end
        for i,func in pairs(t) do
            chr:FindFirstChildOfClass("Tool").Activated:connect(function() 
                --[[plays the function in table "t"]]--
            end)                
        end
    end

1 answer

Log in to vote
1
Answered by 6 years ago
ptypelist = {health = healtheffect(), strength=strengtheffect(), speed = speedeffect()}

function gamescript.potiondrink(chr, effect, config) -- "chr" is Character of the player, "effect" is the folder "Effect", "config" is the configuration folder.
    local t = {} -- Container for the list of effect functions
    for i,v in pairs(effect:GetChildren()) do
        table.insert(t,1,ptypelist[v.Value])
    end

    chr:FindFirstChildOfClass("Tool").Activated:connect(function() 
        for _,f in pairs(t) do
            f(config or whatever args here)
        end
    end)               
end


Ad

Answer this question