How Would I do this in a script?

Hello everyone,

I’m trying to store functions in a server script and I want to call them based on the tool’s type.

I know how to do this in a module script but not sure how to do the same in a normal script

Example:

local Event = RemoteEvent

local function Axe()
 --code here
end

local function Pickaxe()
  --code here
end

Event.OnServerEvent:Connect(function(player,Type)
       -- Let's say for example Type == Pickaxe 
       Type() -- I want this to call the right function based on the type
end)

If you have any questions feel free to ask

Why don’t you use a module script and just require it from this script?

Well the only other possible way (i know of) is like a makeshift module


local function axe()
    — code
end

local function Pickaxe()
  --code here
end

local functions = {
    ["Axe"] = axe,
    ["Pickaxe"] = Pickaxe
}

Event.OnServerEvent:Connect(function(player,Type)
       -- Let's say for example Type == Pickaxe 
       functions[Type]() -- I want this to call the right function based on the type
end)