local NPC = script.Parent.Tori local function VanillaIcecream() local Coordinates = script.Parent.Coordinates.VanillaIcecream.Value NPC.Humanoid:MoveTo(CFrame.p) NPC.Humanoid.MoveToFinished:wait() NPC:SetPrimaryPartCFrame(CFrame) end function game.ReplicatedStorage.Events.SnackToServer.OnServerInvoke(Player,Type) print(Type) Type() end
What I want to do is, you see that there is a function in the script. And then there is a event that is received from a client, with the argument Type. The Type name is called "VanillaIcecream, the same as the function. Is it possible to do Type()/VanillaIcecream()
Output
attempt to call local 'Type' (a string value)
In Lua, functions are variables like any other. What' special about these variables is that they can be invoked by adding parentheses on to the end.
Therefore, they can be passed as arguments to other functions and then called.
Here's an example:
local x = 5 local function fancyPrint(arg) print(arg) end local function someFunction(func, number) func(number) end someFunction(fancyPrint, x)