How to detect mouse and user input from a server script?

Hello, I am trying to make a plugin like F3X but I don’t know how to detect the developer’s / User’s Input.B
“Building Tools by F3X” has a way of detecting when the player/dev clicks a Part, or press a key on the keyboard. Can you please help with this because it is really confusing. Here is the code for more detail:

local IsOn

PluginButton.Click:Connect(function()
	
	IsOn = not IsOn
	
	PluginButton:SetActive(IsOn)
	
	GUI.Enabled = IsOn
	
end)

local Mouse = game.Players.LocalPlayer:GetMouse()

while wait() do
	
	script.Select.Adornee = Mouse.Target
	
	Mouse.Button1Down:Connect(function()
		
		if Mouse.Target then
			
			script.Select.SelectedBox.Adornee = Mouse.Target
			
		end
		
	end)
	
end

(Select is the hover selection box and Selected Box is the selected part’s selection box…)

Output:

You can’t access LocalPlayer from a plugin because the player doesn’t exist.

plugin:GetMouse() is what you should be using for this.

It still isn’t working tho…

it keeps saying this inside the output:

local GUI = script.Parent.CreatePartGUI
local ScrollFrame = GUI.Frame.ScrollingFrame
GUI.Parent = game.CoreGui

local IsOn

PluginButton.Click:Connect(function()
	
	IsOn = not IsOn
	
	PluginButton:SetActive(IsOn)
	
	GUI.Enabled = IsOn
	
	local Mouse = plugin:GetMouse()
	
	Mouse.Move:Connect(function()
		
		script.Select.Adornee = Mouse.Target
		
		Mouse.Button1Down:Connect(function()
			
			if Mouse.Target then
				
				script.Select.SelectedBox.Adornee = Mouse.Target
				
			end
			
		end)
		
	end)
	
end)

You forgot to close one a parenthesis somewhere in your script.

Can you please point out where by quoting it or something because it says line 25 but I checked and it is fine…

Send line 25, since I can’t see 25 lines on the quote. You might be missing something.

local GUI = script.Parent.CreatePartGUI
local ScrollFrame = GUI.Frame.ScrollingFrame
GUI.Parent = game.CoreGui

local IsOn

PluginButton.Click:Connect(function()
	
	IsOn = not IsOn
	
	PluginButton:SetActive(IsOn)
	
	GUI.Enabled = IsOn
	
	local Mouse = plugin:GetMouse()
	
	Mouse.Move:Connect(function()
		
		script.Select.Adornee = Mouse.Target
		
		Mouse.Button1Down:Connect(function()
			
--[[ LINE 25]]if Mouse.Target then
				
				  script.Select.SelectedBox.Adornee = Mouse.Target
				
			  end
			
		end)
		
	end)
	
end)

I can’t see anything wrong with that script, I might be missing something simple though. Are you sure that’s the script that is erroring?

Well @LoadsOfMoney123 I don’t know either, but if you need it then here is the explorer:
image
I put the plugin inside starterGUI I hope that isn’t a problem.

Also it is a local plugin and I right click the folder not the script

Try this and send the output:

local GUI = script.Parent.CreatePartGUI
local ScrollFrame = GUI.Frame.ScrollingFrame
GUI.Parent = game.CoreGui

local IsOn

PluginButton.Click:Connect(function()
	print("Button clicked")
	IsOn = not IsOn
	
	PluginButton:SetActive(IsOn)
	
	GUI.Enabled = IsOn
	
	local Mouse = plugin:GetMouse()
	
	Mouse.Move:Connect(function()
		print("Mouse Moved")
		script.Select.Adornee = Mouse.Target
		
		Mouse.Button1Down:Connect(function()
			print("Mouse clicked")
--[[ LINE 25]]if Mouse.Target then
				  print("Mouse Target")
				  script.Select.SelectedBox.Adornee = Mouse.Target
				
			  end
			
		end)
		
	end)
	
end)

Okay, I edited it and this should show which stage it gets up to.

Nothing happens when I move the mouse…

It only says button clicked and the gui is ok

Could you please send line 37? Edit: Line 25 to line 37.

here:

local PluginButton = plugin:CreateToolbar("Creepersaur's Plugins"):CreateButton("CreatePart by creepersaur!", "Create a new part!", "rbxassetid://5710391838")

local GUI = script.Parent.CreatePartGUI
local ScrollFrame = GUI.Frame.ScrollingFrame
GUI.Parent = game.CoreGui

local IsOn

PluginButton.Click:Connect(function()
	print("Button clicked")
	IsOn = not IsOn
	
	PluginButton:SetActive(IsOn)
	
	GUI.Enabled = IsOn
	
	local Mouse = plugin:GetMouse()
	
	Mouse.Move:Connect(function()
		print("Mouse Moved")
		script.Select.Adornee = Mouse.Target
		
		Mouse.Button1Down:Connect(function()
			print("Mouse clicked")
			--[[ LINE 25]]if Mouse.Target then
				print("Mouse Target")
				script.Select.SelectedBox.Adornee = Mouse.Target
				
			end
			
		end)
		
	end)
	
end)

--[[LINE 37]]GUI.Frame.CreatePart.MouseButton1Click:Connect(function()
	
	local Camera = game.Workspace.Camera
	
	local Part = Instance.new("Part")
	
	local Xpos = ScrollFrame.Xpos.Text
	local Ypos = ScrollFrame.Ypos.Text
	local Zpos = ScrollFrame.Zpos.Text
	
	Part.Position = Vector3.new(Xpos,Ypos,Zpos)
	
	local R = ScrollFrame.Red.Text
	local G = ScrollFrame.Green.Text
	local B = ScrollFrame.Blue.Text
	
	Part.Color = Color3.fromRGB(R,G,B)
	
	Part.Parent = workspace
	
	wait()
	
	local LookDirection = CFrame.new(Camera.CFrame.Position, Part.Position)
	local NewCFrame = CFrame.new(Camera.CFrame.Position) * LookDirection
	Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 1)
	
	Camera.CFrame.Position = Camera.CFrame.Position + Vector3.new(0,23,0)
	
end)

GUI.Frame.CreateMesh.MouseButton1Click:Connect(function()
	
	local Camera = game.Workspace.Camera
	
	local Part = Instance.new("MeshPart")
	
	local Xpos = ScrollFrame.Xpos.Text
	local Ypos = ScrollFrame.Ypos.Text
	local Zpos = ScrollFrame.Zpos.Text
	
	Part.Position = Vector3.new(Xpos,Ypos,Zpos)
	
	local R = ScrollFrame.Red.Text
	local G = ScrollFrame.Green.Text
	local B = ScrollFrame.Blue.Text
	
	Part.Color = Color3.fromRGB(R,G,B)
	
	Part.Parent = workspace
	
	wait()
	
	local LookDirection = CFrame.new(Camera.CFrame.Position, Part.Position)
	local NewCFrame = CFrame.new(Camera.CFrame.Position) * LookDirection
	Camera.CFrame = Camera.CFrame:lerp(NewCFrame, 1)
	
	Camera.CFrame.Position = Camera.CFrame.Position + Vector3.new(0,23,0)
	
end)

Try adding another parenthesis onto line 35. If that doesn’t work I’m not sure why it’s not, sorry.

For some reason It doesn’t work, I deleted all of the mouse stuff, and I added just a script for when you click the plugin button it should just set the adornee of select to the baseplate. When I clicked, NOTHING HAPPENS (it doesn’t set the adornee, the GUI stuff is fine…)

Try printing and see if its actually setting the adornee or the button itself is not working.

Edit: Also, message the reply back since this post is getting very large.

Don’t worry I got it working! (selection boxes do not appear to be working for some reason with a plugin so I used a script to place a block with the EXACT CFrame and size and that seems to be working fine.)
The only problem is when I use a black block to show that you clicked on something using MouseButton1Down it doesn’t work…

That’s good that you got it working, hope you figure out how to get the black block to work.

1 Like