I have this script to draw circles on a SurfaceGui using a tool. Self explanatory:
local Tool = script.Parent
local Handle = Tool.Handle
local Player = game.Players.LocalPlayer
local Character = Player.Character
local function GetFace(Part: BasePart, Direction: Vector3)
local MaxFace = {Face = nil, Vector = nil}
local MaxDot = 0
local MinFace = {Face = nil, Vector = nil}
local MinDot = 0
for i, Face in Enum.NormalId:GetEnumItems() do
local FaceVector = Part.CFrame:VectorToWorldSpace(Vector3.FromNormalId(Face))
local Dot = FaceVector:Dot(Direction)
if Dot > 0 and Dot > MaxDot then
MaxDot = Dot
MaxFace.Vector = FaceVector
MaxFace.Face = Face
elseif Dot < 0 and Dot < MinDot then
MinDot = Dot
MinFace.Vector = FaceVector
MinFace.Face = Face
end
end
return MinFace, MaxFace
end
Tool.Activated:Connect(function()
local Params = RaycastParams.new()
Params.FilterDescendantsInstances = Character:GetDescendants()
Params.FilterType = Enum.RaycastFilterType.Exclude
local ForwardVector = Handle.CFrame.LookVector.Unit
print("Raycast call")
local RaycastResult = workspace:Raycast(Handle.Position, ForwardVector*50, Params)
if not RaycastResult then return end
if not RaycastResult.Instance then return end
print("Raycast success!")
local HitPart: BasePart? = RaycastResult.Instance
local HitPos = RaycastResult.Position
local Normal = RaycastResult.Normal
local MinFace, MaxFace = GetFace(HitPart, Normal)
print(MaxFace.Face.Name)
for i, Constituent in Player.PlayerGui:GetChildren() do
if not Constituent:IsA("SurfaceGui") then continue end
if Constituent.Adornee ~= HitPart then continue end
if Constituent.Face ~= MaxFace.Face then continue end
print("EditableImage found!")
local ImageLabel = Constituent:FindFirstChildOfClass("ImageLabel")
local EditableImage = ImageLabel:FindFirstChildOfClass("EditableImage")
--// Everything works up until this part where even though it doesnt error a circle is never drawn
local RaycastPosVector2 = Vector2.new(HitPos.X, HitPos.Y)
print(RaycastPosVector2)
EditableImage:DrawCircle(RaycastPosVector2, 200, Color3.fromRGB(0, 0, 0), 0, Enum.ImageCombineType.Add)
end
end)
Everything works up until the last part where I have a comment… I don’t really know how to convert the HitPos into a valid Vector2 in a way that the circle shows up. (EditableImage size is (1, 1))