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"

01ptypelist = {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
02 
03    function gamescript.potiondrink(chr,effect,config) -- "chr" is Character of the player, "effect" is the folder "Effect", "config" is the configuration folder.
04        local t = {} -- Container for the list of effect functions
05        for i,v in pairs(effect:GetChildren()) do
06            table.insert(t,1,ptypelist[v.Value])
07        end
08        for i,func in pairs(t) do
09            chr:FindFirstChildOfClass("Tool").Activated:connect(function()
10                --[[plays the function in table "t"]]--
11            end)               
12        end
13    end

1 answer

Log in to vote
1
Answered by 6 years ago
01ptypelist = {health = healtheffect(), strength=strengtheffect(), speed = speedeffect()}
02 
03function gamescript.potiondrink(chr, effect, config) -- "chr" is Character of the player, "effect" is the folder "Effect", "config" is the configuration folder.
04    local t = {} -- Container for the list of effect functions
05    for i,v in pairs(effect:GetChildren()) do
06        table.insert(t,1,ptypelist[v.Value])
07    end
08 
09    chr:FindFirstChildOfClass("Tool").Activated:connect(function()
10        for _,f in pairs(t) do
11            f(config or whatever args here)
12        end
13    end)              
14end
Ad

Answer this question