Can i localize a function? like this:
1 | function SpawnShadow() |
2 | local Shadow = Instance.new( "Part" , workspace) |
3 | Shadow.Position = vector 3. new( 10 , 10 , 10 ) |
4 | Shadow.Name = "Shadow" |
5 |
6 |
7 |
8 | local Shadow = SpawnShadow() |
Can i do that?If not is there another way? because it does not know what shadow is when i create a
1 | script.parent.MouseButton 1 Click:Connect( function () |
try this:
01 | function SpawnShadow() |
02 | local Shadow = Instance.new( "Part" , workspace) |
03 | Shadow.Position = vector 3. new( 10 , 10 , 10 ) |
04 | Shadow.Name = "Shadow" |
05 | end -- need an end to your function! |
06 |
07 | -- not needed. this is only done this way if you're going to call your function from multiple places |
08 | --// SpawnShadow() -- call is good enough! |
09 | -- local Shadow = SpawnShadow() |
10 |
11 |
12 | script.parent.MouseButton 1 Click:Connect(SpawnShadow) -- you can leave off the parenthesis (Round brackets as its not needed here, though calling the function from outside an event you would need them!) |
if you need to look up on how to program in lua id suggest this site: https://www.tutorialspoint.com/lua/index.htm
or the Roblox luau(Similar to lua) wiki: https://developer.roblox.com/en-us/api-reference/class/Script just type in the function or object to get a list of events/functions and properties.
Hope this helps! :)