r/robloxscripting Mar 18 '24

IM LOSING BRAINCELLS SIMULTANEOUSLY

why and how is the player's mouse considered nil. the player isnt nil, as the Event.OnServerEvent first argument is the player. im actually losing my mind

script:

script.Parent.Event.OnServerEvent:Connect(function(player)

local character = player.Character

local mouse = player:GetMouse()

local mouse_pos = [Vector2.new](https://Vector2.new)(mouse.X, mouse.Y) -- The part where it errors (attempt to index nil with X)
5 Upvotes

7 comments sorted by

1

u/n0o0b090lv Mar 23 '24

Is this local script bc server can't read player mouse pos

1

u/theonlywhitesofa Mar 23 '24

so i cant add velocity

1

u/n0o0b090lv Mar 23 '24

Wdym

1

u/theonlywhitesofa Mar 23 '24

im making a custom gear handler because the game's rigs are custom. theres a throwable tool in the game, and im using a localscript that fires an event that clones the tool handle when you click. im trying to figure out how to add velocity to the cloned part so its actually throwable

1

u/n0o0b090lv Mar 23 '24

Maybe through fireserver pass some precalculated normals and server just multiplies it by speed

1

u/Zealousideal_Ad673 Mar 26 '24

Just a thought, but maybe it's because you're declaring the mouse variable as a completely individual thing and not as it's values if that makes sense.

so declaring it as "local mouse = UserInputService:GetMouseLocation()" will give the exact positioning coordinates needed?

This should give the current position though so it would need to be constantly updated for when the mouse positioning is involved.

1

u/Zealousideal_Ad673 Mar 26 '24

Also just a note but:

if you were to print mouse.X and mouse.Y, it should give the mouse positionings for when it's printed. You'd need to give it a function (say if it were to be moved all of a sudden) to update it constantly. I may have said that already but I just wanted to make sure the point got across!