Ad
Log in to vote
0

Can i localize a function?

Asked by 12 days ago

Can i localize a function? like this:

function SpawnShadow()
local Shadow = Instance.new("Part", workspace)
Shadow.Position = vector3.new(10,10,10)
Shadow.Name = "Shadow"



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


script.parent.MouseButton1Click:Connect(function()

1 answer

Log in to vote
0
Answered by
TGazza 558 Moderation Voter
12 days ago

try this:

function SpawnShadow()
    local Shadow = Instance.new("Part", workspace)
    Shadow.Position = vector3.new(10,10,10)
    Shadow.Name = "Shadow"
end -- need an end to your function!

-- not needed. this is only done this way if you're going to call your function from multiple places
--// SpawnShadow() -- call is good enough!
-- local Shadow = SpawnShadow()


script.parent.MouseButton1Click: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! :)

Ad

Answer this question