You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
To get the mouse position for z
-- Client
Tool = script.Parent
UserInputService = game:GetService("UserInputService")
ClientRemote = Tool:WaitForChild("ClientRemote")
Mouse = UserInputService:GetMouseLocation()
UserInputService.InputBegan:Connect(function(Input)
if Input.UserInputType == Enum.UserInputType.MouseButton1 then
local function GetMouseLocations()
Mouse = UserInputService:GetMouseLocation()
return Mouse.X, Mouse.Y
end
ClientRemote:InvokeServer(GetMouseLocations())
end
end)
--Server
Tool = script.Parent
ClientRemote = Instance.new("RemoteFunction")
ClientRemote.Name = "ClientRemote"
ClientRemote.Parent = Tool
ClientRemote.OnServerInvoke = function(Player, MouseX, MouseY)
local Part = Instance.new("Part")
Part.Parent = workspace
Part.Position = Vector3.new(MouseX, MouseY, nil)
end
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
GetMouseLocation returns the mouse’s position relative to the top-left corner of the screen. It does not return the World Space position of your cursor.
Although it’s not advised to use Mouse.Hit.Position, unless you write a custom replacement for this function, it’ll do the job for you.
If you want to use a non-deprecated class, @ProgrammerNovice, you could try raycasting from the player’s Camera:
-- FETCH THE 2D POSITION OF THE PLAYER'S MOUSE ON THEIR SCREEN
local mouse: Vector2 = UIS:GetMouseLocation()
-- FETCH THE CAMERA FOR THE PLAYER
local camera: Camera = game.Workspace.CurrentCamera
-- ACCOUNTING FOR GUI INSET, RAYCAST FROM THE PLAYER'S CAMERA
-- TO A 3D POSITION IN THE WORKSPACE, AT A DEPTH OF 100
local ray: Ray = camera:ScreenPointToRay(mouse.X, mouse.Y, 100)
-- THE 3D POSITION EQUIVALENT TO mouse.Hit
print(ray.Origin)
You dont have to show me a script for me to just copy and paste and then it work i was just on a video learning raycasting, im trying to learn without being shown or copy pasting someones work, thx tho
That wasn’t what I was doing! When trying to teach others, I find it’s beneficial to show snippets of code in practice so people can see how things work. It’s then the individual’s decision as to whether they copy and paste things.