Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game.Players.LocalPlayer or game.Players:GetPropertyChangedSignal("LocalPlayer"):Wait();
- local Mouse = Player:GetMouse();
- local runService = game:GetService("RunService");
- local currentItems = {};
- local function isInFrame(v)
- local X = Mouse.X;
- local Y = Mouse.Y;
- if X > v.AbsolutePosition.X and Y > v.AbsolutePosition.Y and X < v.AbsolutePosition.X + v.AbsoluteSize.X and Y < v.AbsolutePosition.Y + v.AbsoluteSize.Y then
- return true;
- else
- return false;
- end
- end
- local function mouseExited(obj)
- if not obj.MouseIsInFrame and obj.MouseWasIn then
- obj.MouseWasIn = false;
- obj.LeaveEvent:Fire();
- end
- end
- local function mouseEntered(obj)
- if not obj.uiObj.Visible then -- make sure the ui object isnt visible
- if obj.MouseIsInFrame and not obj.MouseWasIn then
- obj.MouseWasIn = true;
- obj.EnteredEvent:Fire();
- end
- end
- end
- runService.Heartbeat:Connect(function()
- for _,obj in pairs(currentItems) do
- obj.MouseIsInFrame = isInFrame(obj.uiObj);
- mouseExited(obj);
- end
- for _,obj in pairs(currentItems) do
- mouseEntered(obj);
- end
- end)
- local class = {}
- function class.mouseClass(uiObj)
- if currentItems[uiObj] then
- return currentItems[uiObj].EnteredEvent.Event, currentItems[uiObj].LeaveEvent.Event;
- end
- local newObj = {};
- newObj.uiObj = uiObj;
- local EnterEvent = Instance.new("BindableEvent");
- local LeftEvent = Instance.new("BindableEvent");
- newObj.EnteredEvent = EnterEvent;
- newObj.LeaveEvent = LeftEvent;
- newObj.MouseWasIn = false;
- currentItems[uiObj] = newObj;
- uiObj.AncestryChanged:Connect(function() -- obj was destroyed
- if not uiObj.Parent then
- EnterEvent:Destroy();
- LeftEvent:Destroy();
- currentItems[uiObj] = nil;
- end
- end)
- return EnterEvent.Event, LeftEvent.Event;
- end
- return class;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement