Hoping I can make this understandable 
A function is something that, when called, will run the code within itself.
print("Hello world")
--Will have the same effect as
local function something()
print("Hello world")
end
something() --calls the function and runs the code within.
--You can also pass things through aswell.
local function something(whatToPrint) --have descriptive words for your args.
print(whatToPrint) --prints 'Fabien is cool!'
end
something("Fabien is cool!")
checkState is a function I created that, when called, returns the state of a given objects “Debounce” attribute. This is the function that is used to check whether we can collect the coins or not. You don’t need a separate function just to do this, but it’s just personal preference.
setState is a function that is created so that we can set said Debounce state of an object. You don’t actually need to create a separate function for this, but I do it as a personal preference. The alternative would be typing
obj:SetAttribute("Debounce", true)
task.wait(3)
obj:SetAttribute("Debounce", false)
It just makes it look cleaner.
When calling ‘checkState(taggedCoin)’, the function returns the current state of the tagged coins debounce (true, false, etc). If you were to declare a variable and call that function as its value, the variable would be set to whatever it returns.
local currentState = checkState(taggedCoin)
--If the debounce is true, currentState will have its value set to true, etc.
The if statement runs the code within itself if the current debounce state [ true or false ] == false.