Making graph placement system

So I’m wanting to make a graph place ment system.

So this code works but there is no graph so I solved this problem by flooring the XYZ values but I can’t figure out how to get each of the values separate. position just gives me all three values put together

  
 
-- Define player objects
local player = game.Players.LocalPlayer
local camera = workspace.CurrentCamera
 
-- Define services needed
local UIS = game:GetService("UserInputService") -- for mouse input
local RunService = game:GetService('RunService') -- for RenderStepped / live input from the user 
local ReplicatedStorage = game:GetService('ReplicatedStorage') -- to define the RemoteEvent
 
local placeEvent = ReplicatedStorage:WaitForChild('Place') -- RemoteEvent to tell server to place object
 
local bed = workspace:WaitForChild('Bed') -- object  being used
 
-- params: X(x position on the screen), Y(y position on the screen), IgnoreList(List of objects to ignore when making raycast)
-- returns: Instance(object that the player's mouse is on), Vector3(position that the player's mouse is on)
function getMousePoint(X, Y, IgnoreList)
    
    -- Create a new set of Raycast Parameters
    local raycastParams = RaycastParams.new()
    raycastParams.FilterType = Enum.RaycastFilterType.Blacklist -- have the mouse ignore objects
    raycastParams.FilterDescendantsInstances = {bed} -- have the mouse ignore the bed
    raycastParams.IgnoreWater = true
 
    local camray = camera:ScreenPointToRay(X, Y) -- get the position on the world relative to the mouse's screen position(x,y)
    
    -- Draw the ray in the world, pointing at wherever the mouse is
    local raycastResult = workspace:Raycast(camray.Origin, camray.Direction * 2048, raycastParams)
    
    -- If the draw failed, or the mouse is pointing at the sky, return nil
    if not raycastResult then return nil end
    
    
    -- Otherwise, return the part and position the mouse is over
    return raycastResult.Instance, raycastResult.Position
end
 
-- [TIP] this was the old way to get the mouse, THIS SHOULD NO LONGER BE USED
local Mouse = game.Players.LocalPlayer:GetMouse()
-- [END OF TIP]
 
UIS.InputBegan:Connect(function(i)
    -- When the user clicks (left mouse button)
    if i.UserInputType == Enum.UserInputType.MouseButton1 then
        -- Get the mouse location using the User Input Service
        local mouseLocation = UIS:GetMouseLocation()
        -- Get the target object and position
        local target, position = getMousePoint(mouseLocation.X, mouseLocation.Y, {bed})
        -- If the target object and position BOTH exist
        if target and position then
            -- Set the bed there for the client, and tell the server
            bed.PrimaryPart.CFrame = CFrame.new(position)
            placeEvent:FireServer(position, bed)
        end
    end
end)
 
-- RenderStepped will run every frame for the client (60ish times a second)
RunService.RenderStepped:Connect(function()
    -- Get the mouse location using the User Input Service
    local mouseLocation = UIS:GetMouseLocation()
    -- Get the target object and position
    local target, position = getMousePoint(mouseLocation.X, mouseLocation.Y, {bed})
    -- If the target object and position BOTH exist
    if target and position then
        -- Set the bed there for the client
        bed.PrimaryPart.CFrame = CFrame.new(position)
    end
end)
1 Like

You can get the separate values by doing position.X, position.Z and position.Y.

I tried that but position is defined weirdly so you can’t do that

local target, position = getMousePoint(mouseLocation.X, mouseLocation.Y, {bed})

I haven’t tried it yet but I might be able to do this

Local pos2 = vector3.new(0,0,0)
pos2 = position
Print (pos2.X)

That should change it from a set of multiple pieces of data into a vector 3