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

How and What Function Help?

Ok I know I may feel stupid when I ask these questions but ok when I use a function I want to know what this could be used for ()?

like this

function playerWhoClicked(whatgoeshere)

end

what goes there that my question like I know when you use a touch function?

function onTouch(hit)
local h = hit.Parent
if h then
print(hit.Parent)
         end
end

well that tells me that the hit.Parent = Player1 when it testing but I don't understand where the hit came from anyway.

How could I do this?

2 comments

0

You'll find this page quite informative, in particular the part about arguments and parameters: http://wiki.roblox.com/index.php?title=Function

0

Try a video I made on functions: https://www.youtube.com/watch?v=XwAxFAc21Xs

2 answers

✓ Accepted answer

Well for 1 the () really don't require anything in there most of the time, however use http://wiki.roblox.com/index.php?title=Function to find out exactally as I'm not sure. As for hit Im assuming you put the script in a part so when you touch that part it will print.

The parenthesis are variables for values. These are defined when you call the function. This is typically when you want the function to use the value and manipulate them in your favor.

function Add(x, y)
    return x + y
end

print(Add(5, 11))

In the script above, the variables of x and y take the place of the values 5 and 11 used in the call on line 5. The function should return the intended result 16. You can also call functions using instances, bools, tables, et cetera.

When you're using an event, the event will automatically get the value for you. All you would have to do is set it as a variable in your function. So if Player1 joins your game and you have a PlayerAdded event listening, the script will automatically get the player who joined.

function PlayerAdded(Player) --Player being the value the event gave us.
    print(Player.Name)
end

game.Players.PlayerAdded:connect(PlayerAdded)

You would want to look through the wiki and find what events will return what values and learn how to manipulate functions in your favor.

######Hopefully this answered your question. If so do not forget to hit the accept answer button. If you have any questions, feel free to comment below.

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