Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Not calling a function?

I got this from roblox wiki. Is the open and close funtion called?

local door = script.Parent
 
function open()
	-- This function will open the door.
	door.CanCollide = false -- Make players able to walk through the door.
 
	for transparency = 0, 1, .1 do
		door.Transparency = transparency
		wait(.1)
	end
end
 
function close()
	-- This function will close the door.
	for transparency = 1, 0, -.1 do
		door.Transparency = transparency
		wait(.1)
	end
 
	door.CanCollide = true -- Make players unable to walk through the door.
end

1 answer

✓ Accepted answer

No, theses function will never run until you call them here a little exemple.

function runningAFunction()
	print("This function is running yay !")
end

runningAFunction()--It will run the function, thats mean you'll see in your output ~"This function is running yay !~

you can also call a function like that

local aFunction = function()
	print("Another function is running :D !")
end

aFunction()--It will run the function, thats mean you'll see in your output ~"Another function is running :D !~

you can put some Settings like that

function sum(a, b)
	return a + b --without return when you're running the function and if you're trying to print the function it'll print a nothing
end

print(sum(5, 5))--It'll print 10 because 5 + 5 is 10 hehe

with return you can return more than one thing like:

function sum(a, b)
	return a + b, "the second object" --without return when you're running the function and if you're trying to print the function it'll print a nothing
end

local theSum, theString = sum(5, 5)

now if you you print like this:

print(theSum, theString)--you'll see in your output 10 and the second object

and now the final result will look like this

function sum(a, b)
	return a + b, "the second object"
end

local theSum, theString = sum(5, 5)
print(theSum, theString)--you'll see in your output 10 and the second object

Now your code here:

local door = script.Parent
local oppened = false -- open the door if  the door is closed or close the door if it's openned
local debounce = false--added debounce for be sure It will not spam the functions

function open()
	oppened = true
    -- This function will open the door.
    door.CanCollide = false -- Make players able to walk through the door.

    for transparency = 0, 1, .1 do
        door.Transparency = transparency
        wait(.1)
    end
end

function close()
	oppened = false
    -- This function will close the door.
    for transparency = 1, 0, -.1 do
        door.Transparency = transparency
        wait(.1)
    end

    door.CanCollide = true -- Make players unable to walk through the door.
end

door.Touched:connect(function()
	if debounce then return end
	debounce = true
	if not oppened then
		open()
	else
		close()
	end
	wait(1)--wait 1 seconde before you can run the other function
	debounce = false
end)

Thats all I know If I don't forget one thing, enjoy !

This discussion is preserved as it was. New answers, comments, and votes are closed.