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

How do you access the player's mouse using this script?

local function playeradded(player) local click = player:GetMouse() if click.Button1Down() and script.Parent.Enabled then script.Parent.Handle.BrickColor = BrickColor.new("Black") wait(1) script.Parent.Handle.BrickColor = BrickColor.new("Fossil") end end

game.Players.PlayerAdded:connect(playeradded)

I am trying to find a way to access the mouse, but I have no idea how. I can't find out how on the wiki because this is what I ended up making from the wiki's information.

2 answers

GetMouse() can only be accessed with a local script. And you would not use a PlayerAdded event. See if you can study this example:

(This is in a local script)

local Player = game.Players.LocalPlayer -- "LocalPlayer" is the client the local script is inside of

local Mouse = Player:GetMouse() -- Returns the player's mouse.

Let me know if you have any questions

A PlayerMouse can only be accessed by a LocalScript. The following is a LocalScript:

local plr = game:GetService('Players').LocalPlayer -- LocalPlayer is the player, in this case the client, using the LocalScript.
local mouse = plr:GetMouse() -- Gets the player's Mouse object and returns it.

mouse.Button1Down:connect(btn1down) -- You can connect a Button1Down event to the mouse.

mouse.Icon = 'http://www.roblox.com/asset/?id=1337' -- Dunno.

As you can see, you can retrieve the mouse using a LocalScript and it behaves exactly like a tool mouse. Changing the Icon and connecting functions to the Button1Down, Button2Down, etc. are the same as in tools. But you MUST use a LocalScript.

If you are confused or have any questions, contact me.

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