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

how to print something if a certain part is hovered over and clicked?

I'm a little confused. pretty sure I can't use a function in a if statement like I did but I don't know the alternative. basically just trying to print "done" if the part is hovered over by the mouse and clicked. any help would be appreciated


local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local function clicked()
	mouse.Button1Down:connect(function()
		
	end)
end


mouse.move:connect(function()
	
	if mouse.Target == game.Workspace.Part and clicked() then
		print("done")
		
		end
	
end)

1 answer

✓ Accepted answer

There are many ways to achieve this but the easiest would be by adding a clickdetector to the part and then using the MouseClick event

example:

local part = workspace.Part
local ClickDetector = Instance.new("ClickDetector") -- u can add the clickdetector manually into workspace or using script, your choice
ClickDetector.Parent = part

ClickDetector.MouseClick:Connect(function()
	print("done")
end)

see this article over clickdetector

and u can use functions in if statements

6 comments

0

How would I be able to script it so that it requires the mouse to be hovering over the part and getting click to print done?

0

what u mean if you click it then ur hovering over the part but noone the less

0

use this event to add the click event and then

0

remove the click event use this event https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseHoverEnter but do you understand click dectector, it makes the partent clickable and able to respond to a mouse events ?

0

my bad i ment to paste this event https://developer.roblox.com/en-us/api-reference/event/ClickDetector/MouseHoverLeave use this even to remove the click event, but still i dont get why u would want to do this

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