Need help with mouse detection

I need help switching a script of mine, so instead of pressing a key to enable and disable a particle, pressing the mouse and releasing it is how it should function.

local userInputService = game:GetService("UserInputService")
local particles = workspace.LightningC.cannon.particleCore


function emit()
	for number,index in pairs(particles:GetChildren()) do
		if index:IsA("ParticleEmitter") then
			index.Enabled = not index.Enabled
		end
	end
end

userInputService.InputBegan:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.C then
		emit()
	end
	
end)

userInputService.InputEnded:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.C then
		emit()
	end
	
end)

Any help is appreciated! :slight_smile:

1 Like

Have you looked at the create.roblox.com page?
UserInputService | Roblox Creator Documentation

1 Like

Maybe looking into the documentation the first example is this

if input.UserInputType == Enum.UserInputType.MouseButton1 then
         print("The left mouse button has been pressed!")
end
2 Likes

An extra question, if possible.

Is there a way to make the part where the particles are connected, follow the cursor?

Follow the cursor in 3d space or 2d space like a GUI?

I would try with RunService renderStep connection, to update the CFrame of the part to follow the cursor on a 3d environment by a raycast.

If its 2d GUI case, then use the Mouse properties
image

Its for 3D space.

Like a normal baseplate.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.