How could I achieve this:
if #myTable == 2 then
local Rod = Instance.new("RodConstraint")
for i, v in myTable do
Rod.Attachment0 = ?
Rod.Attachment1 = ?
end
end
What if my table looks like this?
Thanks!
How could I achieve this:
if #myTable == 2 then
local Rod = Instance.new("RodConstraint")
for i, v in myTable do
Rod.Attachment0 = ?
Rod.Attachment1 = ?
end
end
What if my table looks like this?
Thanks!
try doing:
Rod.Attachment0 = myTable[1]
Rod.Attachment1 = myTable[2]
or
local Index = 0
for _, Attachment in pairs(myTable) do
Index += 1
if Index == 1 then
Rod.Attachment0 = Attachment
elseif Index == 2 then
Rod.Attachment1 = Attachment
end
end
sadly, my table doesn’t have an index. print(i) returns an instance
you can still make an Index by doing the following:
local Index = 1
for i, v in AttachmentArrowsTable do
--// your code here
Index += 1
end
just make sure the Index
gets increased at the bottom of the loop.
try doing that and let me know if it works or not.
isn’t that what my code already does? I just used attachment1
as the index
oh, I guess you’re right.
Also, what was the problem with your code, again?
Since from what I see, it looks like your code is working?
it is working… but I feel like it could be much simpler and better lol
but if it’s already as good as it can get, that’s fine too
I mean, if it works it works
what are you trying to do? what you have works fine lol
I’d like it to be simpler and more optimized
Can you show me how your table is formed? Its a key-value pair (dictionary) with the instances as the key - but whats the value?
local AttachmentArrowsTable = {}
local function addAttachment(part)
if part:FindFirstChildOfClass("Attachment") then
AttachmentArrowsTable[part] = AttachmentArrows:Clone()
end
end
mouse.Button1Down:Connect(function()
addAttachment(mouse.Target)
end)
Here’s how the part that is the mouse.Target looks like:
Thanks!
So what is attachmentarrows? The part you’re trying to weld?
By any means, it doesn’t seem like you’re using the values - atleast not from what I can see. Try changing to a regular table, at which point you can use table.unpack() to separate the values.
Furthermore, you can create a table of your Dictionary Keys by using a function as follows
local function TableFromDict(D)
local t = {}
for k,_ in pairs(D) do
table.insert(t,k)
end
return t
end
The weld constraint basically holds the part to the frontweight. Let me just grad a video for you real quick. I think you’ll get what the attachment arrows are there for:
yep, this is perfect, thank you!
also, thank you for being so quick, it’s 3 am for me and I really want to sleep lol
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.