Hi fellas, so recently I’ve come across an issue within my game that just kinda spontaneously came out of nowhere.
The other day I was working on a project that involved the mouse, which, at the time, worked fine. I’ve logged on after a few days of absence to find that it no longer works.
To give some context, I was using mouse detection within my code, and it was picking up the mouse just fine, now that I’ve logged on, it’s consistently refusing to pickup the mouse, returning nil indefinitely.
I was using
players.LocalPlayer:GetMouse()
to get my mouse, which worked fine a few days ago. Now it doesn’t seem to be detecting the mouse at all, in neither Studio nor Player, and yes. I am also using a LocalScript, and have tried in both StarterPlayer and StarterCharacter script folders.
Any ideas on what might have caused this and how I can remediate this? If it’s any help, the supporting code that assigns the mouse to the variable is encompassed within the following event as so:
(This worked a few days ago, so I’m highly doubting this code is the issue, but I haven’t caught up too frequently with any LuaU changes, so I could be wrong)
My guess would be that CharacterAppearanceLoaded doesn’t fire. Is there a particular reason you have it inside there? If you move the variable outside of that function, it should work just fine
Of course, only reason I keep it in there is because I tested it before without, and the :GetMouse() function would fire before the character was loaded, therefore leaving the variable nil indefinitely regardless anyway. CharacterAppearanceLoaded was working fine the other day, so I’ve got no idea why it’s not firing now.
:GetMouse() is a method of Player, so the Character shouldn’t have anything to do with it returning nil. Try this in a LocalScript parented in StarterGui
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
print(mouse)
I would, however, a lot of the other code I am currently using alongside the mouse detection wouldn’t work under StarterGui, at least not in the way I am intending for it to be used.
I think I have a better grasp on the situation though, so I’ll try a few things tomorrow. I still think CharacterAppeareanceLoaded is bugging though, as it was working 3 days ago, and I tried it today from an autosave file where I had it working and it suddenly wasn’t, but if I can make it work then it isn’t really worth losing sleep over.
Cheers though. Much appreciated mate.
Quick update, fixed it. Changed CharacterAppearanceLoaded to just CharacterAdded and that worked a charm. Was really just an easy solution and I feel dumb for not trying it sooner