Normally, I would advise against busy loops, however in this case there simply is no alternative to a busy loop because I don't think Camera.Changed fires for attach. If I'm wrong, tell me and I'll adjust the script to get rid of the busy loop.
local ChangedEvent = Instance.new("BindableEvent");
local lastHit;
local Mouse = game.Players.LocalPlayer:GetMouse();
Mouse.Moved:connect(function()
if Mouse.Hit ~= lastHit then
lastHit = Mouse.Hit;
ChangedEvent:Fire(lastHit);
end;
end);
while wait(0.08) do
if Mouse.Hit ~= lastHit then
lastHit = Mouse.Hit;
ChangedEvent:Fire(lastHit);
end;
end;
How to use:
To get the event for the Hit changing, use ChangedEvent.Event:connect()
How does it work?
We look for the Mouse moving, or just occasionally checking the mouse hit, and comparing it to the hit on the previous comparison. If it is different, we change the value for the last comparison and fire the fake Changed event.
4 comments
If the Player moves without the Mouse being touched.
If the part the player is looking at moves or the player moves without touching the mouse then it won't change
Thanks for the input, I should have thought this through more.
Couldn't you just check if the X or Y property is different when the mouse moves instead of using Hit?