Mouse Teleportation Question/Help

Hello, I was wondering why whenever I teleport a player to the mouse’s current position, it’ll just teleport somewhere random. I’m fairly new to using this language so I don’t exactly know if I’m doing this entirely wrong.

I’ve tried using Mouse.X, Mouse.Y and it works, but the player won’t teleport it to where the player wants it to.

Script:

local Mouse = Player:GetMouse()

Player.Chatted:Connect(function(message)
	if message == "Dimenso" then
		Notification(PlayerGUI.Server.Notification, "Press E to teleport.")
		UIS.InputBegan:Connect(function(input)
			if input.KeyCode == Enum.KeyCode.E then
				game.Players.LocalPlayer.Character:MoveTo(Vector3.new(Mouse.X, Mouse.Y))
				print("position set")
			end
		end)
	end
end)

Mouse.X and Mouse.Y are the position on your monitor, not the position in the world.
Search for posts about aiming a gun using a mouse and you can find information about how to convert mouse position on the screen to world space.

1 Like

Is it called raycasting? I’ve heard of it before but never looked into it.

This post might help: How can I get the mouse’s position in 3D space without using the Mouse object? - Help and Feedback / Scripting Support - DevForum | Roblox.

1 Like

Funny enough I just viewed that and it fixed my problem. Thanks so much!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.