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

I can't Use mouse as an argument?

So I'm trying to make a script where you click on any brick in the game and a GUI box pops up. I successfully made an importer script that puts this script in PlayerScripts for every player that joins the game, but now I'm having trouble actually making this script work. Again, the goal of this script is when a player right-clicks on any brick in the game a GUI box pops up on their screen. Am I not supposed to use mouse as an argument for onButton2Down()? I tried (part) as well but that didn't work either. The script seems like it would work except in the connection line at the bottom it isn't recognizing mouse. How can I fix this?

local SCREENGUI = script.ScreenGui
local FRAME = SCREENGUI.Frame

function onButton2Down(mouse)
	local targ = mouse.Target
	FRAME.Visible = true
	--mouse.Button2Down:connect(function()
	--	onButton2Down(mouse)
	--end)
end 

mouse.Button2Down:connect(onButton2Down)

1 comment

1

mouse is undefined.

1 answer

Use the :GetMouse method to get the mouse, as the mouse is undefined in this script.

local sGui=script.ScreenGui
local frame=sGui.Frame
local player=game.Players.LocalPlayer
local mouse=player:GetMouse()

local function onRightClick()
	local targ=mouse.Target
	frame.Visible=true
end

2 comments

0

It doesn't need a connection line?

0

I don't think so.

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