So it’s not really gamebreaking or anything, but it’s annoying to see this error.
i have a dashing system which lets you dash onto a certain part (again, it works with no problems)
but the weird thing is that sometimes it randomly throws the following error:
yet, in the code i have this line
why does it happen? how is that even possible to begin with since it isn’t accepting input if Mouse.target is nil
Instead of flaming everyone, read this topic: About the Scripting Support category.
You need to show more code, and not in screenshot form. We said that it’ll be nil if your mouse is over the skybox because there isn’t an object.
It’s even worse when you decide to be immature about the answers. Instead of acting like a toddler, I suggest you edit your reply to be more appropriate and polite to the conversation.
I’m stating the obvious here, Mouse.Target will return nil when it’s pointed towards the skybox.
But by the lack of code you have shown us, I would think it would be something outside of this check. Would I be correct that to say that this is wrapped in an event? It would be nicer to see more code rather than a screenshot of two lines.
EGebAHBEH it seems like you’re very chidlish eEeEe!
Please refrain from writing posts like this because it makes people not WaNT tO heLP yOu ( no offense EHebA )
Your issue is that target is probably becoming nil after the check, please do consider that you refrain from such childish acts on this forum.
I would suggest putting Mouse.Target as a local then checking if it exists.
After a quick internet search and attempting to reproduce your error, you’re indexing nil with ‘Name’ ( mouse.target ) so do my suggestion and it should work.
You should provide the whole code and the whole error message. It’s impossible to determine if the error originated within that structure or not based on what you’ve provided.
If you yield at all (possibly by using an API that you didn’t realise yielded) it’s possible the mouse target is nil next time you try to use it.
local players = game:GetService("Players")
local plr = players.LocalPlayer
local mouse = plr:GetMouse()
wait(5)
local target = mouse.Target
print("Mouse target captured:", target)
print("Waiting 3 seconds...")
wait(3)
print("The captured mouse target is still", target)
target will stay the same even if the player moves their mouse off the target during the wait. you can test this with a local script in studio yourself.
i don’t understand what you mean by this. every time a new target need to be captured, you would just do
I don’t think you really understood what I was trying to come across.
That code could run each time the mouse moves; so it doesn’t only run once.
But by saving or making a variable point to the mouse’ current target, we can be assured we can do whatever we want with that object for the rest of the conditions we want to test, or whatever else we want to do. By doing this we know there’s not a chance it could become nil at some point later in our code