Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

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? SWBTyresse 50 — 4y
0
what u mean if you click it then ur hovering over the part but noone the less VerdommeMan 1479 — 4y
0
use this event to add the click event and then VerdommeMan 1479 — 4y
View all comments (2 more)
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 ? VerdommeMan 1479 — 4y
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 VerdommeMan 1479 — 4y
Ad

Answer this question