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

Can you make custom function like things?

Asked by
ultrabug 306 Moderation Voter
10 years ago

Basically what I am asking is if you can make custom 'functions' in a script and then later call them. I think it is possible but if so I don't have much of an idea of how to do so. Here is how I think it would work.

local function1=function()
    for i,v in pairs(game.Players:GetChildren()) do
        v.Character.Torso:Destroy()
    end
end

Any help?

0
Just a tip, functions are already local variables (as they cannot be called outside the scope that they are declared in.) You can store a function as a global by putting "_G." before the name. nate890 495 — 10y
0
That is not true. A local variable and a global variable have nothing to do with _G. TheLuaWeaver 301 — 10y

1 answer

Log in to vote
3
Answered by 10 years ago

A function is something you call when you need the it to run.

Ex.

function Run(Player) 
    print(Player.Name .. " has entered the server");
end

game.Players.PlayerAdded:connect(function(Player)
    Run(Player) 
end)
Ad

Answer this question