I'm attempting a placement system, and I'm trying to get a vector3 position from a player's mouse position.
COMMUNITY QUESTION
How do I convert a UDim2 into a Vector3?
1 answer
Use mouse.UnitRay and create a ray instead.
This is what i do in my script
-- Some variables are outside of this
RunService.Heartbeat:Connect(function()
local mouseRay = Mouse.UnitRay
RayInfo.FilterDescendantsInstances = {Tycoon, Character}
RayInfo.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = game.Workspace:Raycast(mouseRay.Origin, mouseRay.Direction * 1000)
if raycastResult then
local hit = raycastResult.Instance
if hit and not string.find(hit.Parent.Name, "Tycoon") then
if hit:IsA("Part") and hit.Name:lower() == "baseplate" then
goodToPlace = true
SetModelBrickColor(Tycoon, BrickColor.new("Bright green"))
else
goodToPlace = false
SetModelBrickColor(Tycoon, BrickColor.new("Really red"))
end
local Pos = raycastResult.Position
local X = Pos.X
local Y = Pos.Y
local Z = Pos.Z
X = Round(X)
Z = Round(Z)
local newCFrame = CFrame.new(X, Y + yBuildingOffset, Z)
Tycoon:SetPrimaryPartCFrame(newCFrame)
end
end
end)
1 comment
0
That didnt came out good
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
There is a property in the mouse which tells you cframe and position. read more about it here: https://developer.roblox.com/en-us/api-reference/class/Mouse
Position is X and Y.