I’m trying to create the likes of a plugin that will add a part relative to the position and rotation of a certain part. (for example, 3 studs back, 2 studs up, with the Front surface of the part matching that of another part). How would I do that?
Currently, my script creates a sign part at a certain position, but will not follow the rotation and is also not where I want it to be. Would I use CFrames… etc?
if not game.Workspace:FindFirstChild("NamePartFolder") then
local folder = Instance.new("Folder")
folder.Parent = game.Workspace
folder.Name = "NamePartFolder"
end
local label = game.ReplicatedStorage.SectionSign
for i, v in pairs (game.Workspace:GetDescendants())do
if v:IsA("BasePart") and v.Name == ("main") then
local sign = label:Clone()
sign.Parent = game.Workspace.NamePartFolder
sign.Position = v.Position
sign.SurfaceGui.TextLabel.Text = v.Parent.Name
end
end```
So you want a sign to be positioned and rotated relative to your main part? Like you change the cframe of your sign to be 3 studs along another part’s upvector no matter where the upvector is pointing at?
This is easy. All you have to do is, whenever you position the part, just say OriginalPart.CFrame +… and then whatever the position of the relative part is
I want it to place the sign at “main” first, and then rotate it to face “main” 's left surface, and then offset it by an amount of studs
local label = game.ReplicatedStorage.SectionSign
for i, v in pairs (game.Workspace:GetDescendants())do
if v:IsA("BasePart") and v.Name == ("main") then
local sign = label:Clone()
sign.Parent = game.Workspace.NamePartFolder
local sp = Vector3.new(v.Position)
local tp = v.Parent.main.Position
sign.CFrame = CFrame.new(sp, tp)
-- local cf = CFrame.new(v.Position)+Vector3.new(0,5.5,7)
sign.SurfaceGui.TextLabel.Text = v.Parent.Name
sign.Name = v.Parent.Name
end
end
First, set the position of the object of course to the sign, then set it’s Orientation facing the left-side of the object (I don’t know which way the object is facing so that is up to you in the Workspace) and then add a new Vector3.new() value to the objects position to move it in the direction you’d like.