Mouse.Hit not working?

So I tried to make a fly script for my admin commands system and I got this error

Heres my code:

elseif args[1] == "fly" then
		if Players:FindFirstChild(args[2]) then
			local Player = Players:FindFirstChild(args[2])
			local Mouse = Player:GetMouse()
			local Character = Player.Character
			local Head = Character:WaitForChild("Head")
			local BodyVel ="BodyVelocity",Head)
			BodyVel.MaxForce =,math.huge,math.huge)
			BodyVel.Velocity = Mouse.Hit.lookVector * 100

You can only call Player:GetMouse() from within a local script, and I would guess that’s probably the reason it results in nil.

You’ll have to use the same loop in a LocalScript and then return the Mouse object to the regular server Script using a RemoteEvent.

I can elaborate further if you’d like, but that should fix the issue.

1 Like