For this you can simply create a coordinate plane with the origin of it being where you clicked. I'm going to assume you want the random teleporting to only range between the X and Z axis (since it'd be on a 2D surface), so I'll give an example of that.
Getting the Vector3
First, we're going to want to get the Vector3 position of where the user clicks. For this, we can use the "p" property of CFrame, which is what Mouse.Hit returns.
01 | local Player = game.Players.LocalPlayer |
02 | local Char = Player.Character or Player.CharacterAdded:wait() |
03 | local Mouse = Player:GetMouse() |
04 | local Torso = Char:WaitForChild( 'Torso' ) |
06 | local RangeOffsetXZ = 20 |
08 | Mouse.Button 1 Down:connect( function () |
09 | local MouseCF = Mouse.Hit |
10 | local Origin = MouseCF.p |
11 | local NewPos = Origin + Vector 3. new(math.random(-RangeOffsetXZ/ 2 ,RangeOffsetXZ/ 2 ), 0 ,math.random(-RangeOffsetXZ/ 2 ,RangeOffsetXZ/ 2 )) |
13 | Torso.CFrame = CFrame.new(NewPos) |
Hope this helped, let me know if you have any questions.