I don’t want to use a mousedetector, and I don’t think that a constant loop & or mouse move function would be the best. I’m wondering what the best way to detect if a user is hovering over an object and if they are a gui will pop up. This object must be certain one (btw)
By object, I believe you mean a BasePart?
Oh sorry. Yes, I was mainly thinking of an object like a gun or something but in reality it is a basepart.
If so, your best bet would be binding a function to Mouse.Move()
. It shouldn’t impact performance in any major fashion.
Following on from what @Kiansjet said, you could do the following:
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
-- Model containing baseparts we can mouse over
local HoverModel = workspace.HoverableObjects
Mouse.Move:Connect(function()
local Object = Mouse.Target
if Object:IsDescendantOf(HoverModel) then
-- Do stuff, e.g. show a tooltip GUI
end
end)
Don’t use PlayerMouse. Use a UserInputService alternative. PlayerMouse is probably going to become deprecated.
I’ve never worked with binding functions to mouse movements, but there should be an event to help you here:
Hopefully someone has an explanation of how soon.
Don’t use something that works to solve this exact problem because it might become deprecated? That’s a bit daft.
Seems like pretty solid reasoning to me, seeing as a member of the Roblox staff recommends not using it.
Using RunService or something
With the above method OR InputObject.Position (only the X and Y properties)
Don’t forget to check if the input type is UserInputType MouseMovement
The latter you could consider better but it doesn’t update when objects move
My open source StudioMouse module replicates PlayerMouse behavior using UserInputService. This would be ideal code to study for that purpose if you or OP are interested!
Oh, didn’t know about that!