I’ve seen a few topics explaining parameters and I’ve read about them on developer.roblox.com, but I don’t fully understand them.
I have experience using them for example:
local function keyPressed (input, isTyping)
if input.KeyCode == Enum.KeyCode.Q and not isTyping then
SomeEvent:FireServer(mouse.Hit.p)
end
To further specify, I get how to use parameters like player, and how to call a function and send and receive parameters like I did above, but I’m just confused on whether parameters are already set in stone like the parameters “player” and “char” and how Roblox Studio can use both “char” and “character”.
An example of what confuses me:
function damage(hit)
if hit.Parent ~= char then
if hit.Parent:FindFirstChild("Humanoid") then
etc.
end
Part.Touched:Connect(damage)
I guess what I want to find out is if the function above would work if I changed “hit” to “touch” or some other variable, as well as if there is a list of parameters.
“I’m just confused on whether parameters are already set in stone like the parameters “player” and “char” and how Roblox Studio can use both char and character”
Not every parameter / argument is set in stone only some are. You can pass parameters through functions.
e.g
A custom function you can make with no “Set in Stone” parameters.
function joe(JoeSays) -- This is a custom function, which doesn't have "Set in stone" parameters.
print(JoeSays) -- Will print "Hello"
end
joe("Hello") -- We pass through what we want joe to say
A function Roblox provides, because it needs specific parameters for you to find who triggered the function
game.Players.PlayerAdded:Connect(function(Player) -- Player can be named anything, but will always be your player
print(Player) -- Will print your player's name
end)
I hope this solved your confusion. If you have any more questions, please be sure to reply.
They are objects, strings, numbers, tables, etc being named as a variables. They are thrown in order and stay in the same order when you name them. ROBLOX has built in functions that always return a argument. You can name this arg whatever you want. Also, I should mention everything that is inside the parameters are considered arguments.
Events pass things through parameters automatically (in terms of a custom event it’s your choice) and the name is entirely up to you as @JustNylo said, but the information cannot be changed based on what you enter.
For example:
game.Players.PlayerAdded:Connect(function(Player)
print(typeof(Player)) -- will print player
Player:Kick("you got kicked")
end)
This code will work.
game.Players.PlayerAdded:Connect(function(robux)
print(typeof(robux)) -- will print player
robux:Kick("you got kicked")
end)
This code will also work. It’s pretty much identical to a variable, you can name it whatever you want, but the name doesn’t change the object listed in the variable, much like what’s passed through in an event, or what you choose to pass through in a custom event of your own (RemoteEvent, BindableEvent etc.)
Object sent doesn’t change, name of object being recieved can be changed, but not the object by it’s core. Basically, it won’t change the object on the sending end regardless of the name put in on the recieving end. i used to think it was just magic