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

How would I get the player from mouse?

I need to get the player in order to make my script work however, I don´t know how to "get" the player from their mouse. Here´s my script.

Tool = script.Parent
Handle = Tool:WaitForChild("Handle")

Tool.Equipped:Connect(function(player)
	player.Hidden.Tool.Value = 1
end)

Tool.Unequipped:Connect(function(player)
	player.Hidden.Tool.Value = 0
end)

3 comments

0

Is this a script or localscript?

0

Script

0

The output keeps telling me that hidden isn´t a child of mouse

2 answers

✓ Accepted answer

Tool.Parent would be your character, then use GetPlayerFromCharacter to get the player itself.

Alright, so, let's see

A tool should typically have a localscript, because those are the ones you should be using to interact with the client, so first things first move the code to a localscript.

After you have that, you can just use

local Player=game:GetService"Players".LocalPlayer

to figure out which player the script is running for, and then use remote events and functions where necessary in order to interact with the server.

I hope these wiki articles can help you get used to communicating between local and server scripts.

https://developer.roblox.com/en-us/articles/Converting-From-Experimental-Mode

https://developer.roblox.com/en-us/articles/Remote-Functions-and-Events

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