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

What's stored inside "Entity" of this code: "tool.Equipped:connect(function(Entity) end)" ?

Asked by 7 years ago
Edited 7 years ago

Hi guys, as stated in the title, what parameters were stored inside of "tool.Equipped:connect(function(Entity) end)"? I was trying some really simple stuff like printing the name of the player who've equipped that tool without using localscript. It seems that it returns "nil" here's what I did:

Placed a tool consisting of a script, and a part named "Handle" , inside of starter pack. Here's my code:

tool = script.Parent     --Refers to the tool itself
handle = tool.Handle     --Refers to the part named "Handle"

tool.Equipped:connect(function(Entity)
    local player = Entity.Parent  --Parent of the equipped tool should be the player right?
    print(Entity.Name)   --This should display name of player
end)

The above code prints out "Instance"

When using something like game.Workspace.Part.Touched:connected(function(Entity) end), it seems to be storing the parameters of whichever entity that triggers this event as a variable of sorts inside "Entity", hence I can do something like:

game.Workspace.Part.Touched:connected(function(**Entity**) 
    print(Entity.Name)  --Displays the whatever legs touching the part

--And if i want to display the username--
    local player = Entity.Parent
    print(player)
end)

2 answers

Log in to vote
1
Answered by 7 years ago

Hey lesliesoon,

Tool.Equipped() has an optional parameter of Mouse. So, Entity is the Mouse of the player that equipped the tool. You can find more information on this here, and also, you know that you can find the parameters of a function by simply searching it up on the wiki. Just search the object itself, and go to the API page on the wiki, and then scroll down to events and find the event that you are looking for, like here.

Well, I hope I helped, and thanks for reading this if you did.

~~ KingLoneCat

0
Like he said, it's the Mouse. Mouse is nil on the server, because mouses are client-side objects. If you use a LocalScript, you can get the player via game.Players.LocalPlayer Thundermaker300 554 — 7y
Ad
Log in to vote
0
Answered by 7 years ago

Ok thanks, and yes I've already checked that wiki page but the information from the wiki were way too brief, and i didn't quite get it. Take this touched event here as an example. It does tell me that the the parameter used was "otherPart", which is of type base part, but it did not state that any objects touching that part will have its parameters stored inside "otherPart".

I know I'm probably reading something wrong and it would be great if you could correct me on what I should be looking at. I'm usually having trouble with using information from the wiki site.

0
If by another part's parameters, you mean it's properties, then you need to understand that every time an object is passed through as a parameter of a function, all of its properties at the time the function is called are passed through the object. It passes an ObjectValue, so all you need to just do is treat it like it's any other object in the game. KingLoneCat 2642 — 7y

Answer this question