Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How and What Function Help?

Asked by 8 years ago

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?

0
You'll find this page quite informative, in particular the part about arguments and parameters: http://wiki.roblox.com/index.php?title=Function BlackJPI 2658 — 8y
0
Try a video I made on functions: https://www.youtube.com/watch?v=XwAxFAc21Xs ScriptGuider 5640 — 8y

2 answers

Log in to vote
0
Answered by 8 years ago

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.

Ad
Log in to vote
0
Answered by
M39a9am3R 3210 Moderation Voter Community Moderator
8 years ago

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.

Answer this question