In order to get information such as username,id,profile picture for the player equipped, the script would have to be like this right?
tool.equipped:Connect(function(player)
In order to get information such as username,id,profile picture for the player equipped, the script would have to be like this right?
tool.equipped:Connect(function(player)
Sorry for the late reply. No, that returns the player’s mouse, but because the tool will be parented to the character if equipped, using script.Parent.Parent then :GetPlayerFromCharacter() will get the player, which then you’ll have access to such things.
Use my code I provided above and merge it with the original
Ah this makes so much sense now! Thanks.
It has successfully worked! Mind if I ask a few questions so I can further my understanding?
Correct me if I am wrong but this is my understanding of the script.
script.Parent.Unequipped:Connect(function()
This is an OnServerEvent that connects to this function whenever the tool is unequip. You previously mentioned tool.equipped:Connect(function(player)
returns the player’s mouse, what does that mean or do?
if not player then return end
What is the difference between using return
and return end
Thanks, I am fairly new to scripting and I just want to confirm and further my understanding of this script.
Unequipped is not an OnServerEvent but an Event (99% sure it’s called that I’m terrible with most scripting vocabulary other than variable types). It’s built in and can be used by scripts on both the server and the client.
No clue why it returns the player mouse. My best guess is for classic roblox scripts and stuff. As for the second question. return and return end have no difference. I just stuffed the if then statement in one line of code. It could be rewritten as:
if 1 + 1 == 3 then
return
end
Return simply cancels the current function, and, if a variable is called in the function returning a variable will set the called variable to the returned value. For example:
local function a()
end
local function b()
return
end
local function c()
return “hi”
end
local hello = a()
print(hello) --nil
local hi = b()
print(hi) --nil
local hey = c()
print(hey) --hi
Be sure to mark a solution for future users to look at!
Alright man! Thanks for the explanation and help.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.