astraIboy
(The Batman)
July 11, 2022, 8:47pm
#1
So I have this table and i want to set a scripts source but it’ll telling me i cant pass it through because its an array
local keyframe = {
["Left Arm1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Right Arm1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Left Leg1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Right Leg1"] = {
["Position"] = nil,
["Orientation"] = nil
}
}
msix29
(msix29)
July 11, 2022, 9:07pm
#2
It must be a string so
ill use [[ ]] so i can create a multi-line string.
script.Source = [[local keyframe = {
["Left Arm1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Right Arm1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Left Leg1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Right Leg1"] = {
["Position"] = nil,
["Orientation"] = nil
}
}]]
astraIboy
(The Batman)
July 11, 2022, 9:08pm
#3
Alright but how would I change those nils to their own values?
msix29
(msix29)
July 11, 2022, 9:09pm
#4
They will be set to nil and not a string its just the format that roblox requires to change the source of a script.
astraIboy
(The Batman)
July 11, 2022, 9:10pm
#5
Yeah I know they will be set to nil but is there anyway that I can like pass a variable inside of those strings?
msix29
(msix29)
July 11, 2022, 9:11pm
#6
You can change the values to whatever you want. I dont quite understand you, more explanation maybe?
astraIboy
(The Batman)
July 11, 2022, 9:13pm
#7
So basically I have a keyframe table outside and I change it’s values before I set the source, how can I transfer those values?
If you want a direct reference to the exact same table (memory position and everything), you’ll need to create a function to consume it
script.Source = [[local function Consume(table)
...
end
return Consume]]
If you don’t mind the object being a different table memory wise, do what msix suggested.
astraIboy
(The Batman)
July 11, 2022, 9:16pm
#9
Im confused, Consuming? Could you give a little bit more info please?
When you create a table, it is allocated a memory location. If you then create a copy of that table by data, it wont equal the other table since their memory locations are different.
This is different to passing a reference to the table which will result in both scripts having the same table
What you want, however, is to create a new table in a module script using Script.Source, and this can simply be done by writing your table as normal, but wrapping it in a [[ ]]
block, for example:
script.Source = [[local cat = {
Meow = 5
Greeting = "meow"
}]]
msix29
(msix29)
July 11, 2022, 9:18pm
#11
Type the same table when setting it and thats it?
astraIboy
(The Batman)
July 11, 2022, 9:21pm
#12
@msix29 @metatablecatmaid
Guys I’m sorry it’s reallly hard to explain but, okay so basically I am changing the original keyframe table like this
local keyframe = {
["Left Arm1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Right Arm1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Left Leg1"] = {
["Position"] = nil,
["Orientation"] = nil
},
["Right Leg1"] = {
["Position"] = nil,
["Orientation"] = nil
}
}
for i,v in pairs(workspace.astraIboy.HumanoidRootPart:GetChildren()) do
if v:IsA("Attachment") and keyframe[v.Name] then
keyframe[v.Name].Position = v.Position
keyframe[v.Name].Orientation = v.Position
end
end
The reason I cant set it manually is because i dont know what the value is gonna be ever
Do you guys understand now?
msix29
(msix29)
July 11, 2022, 9:29pm
#13
Ohhh alright i think you should use JSONEncode and Decode room change the table till a script so you make it as the source and change the source back as a table with JSONDecode
astraIboy
(The Batman)
July 11, 2022, 9:33pm
#14
Wait so your saying json encode the table, then set the source to that and then get another script and json decode that script’s source?
msix29
(msix29)
July 11, 2022, 9:36pm
#15
No no from same script when u encode it do
Script.Source = JSONDecode(script.source)
Just after one another so it happens fast
astraIboy
(The Batman)
July 11, 2022, 9:38pm
#16
Ohhh okay, I did it but it gave me this error?
local mod = Instance.new("ModuleScript")
mod.Parent = workspace
mod.Source = HttpService:JSONEncode(keyframe)
mod.Source = HttpService:JSONDecode(mod.Source)
msix29
(msix29)
July 11, 2022, 9:40pm
#17
Oh right ENCODE returns a string hmmmmm
1 Like
astraIboy
(The Batman)
July 11, 2022, 9:41pm
#18
Oh my gosh this is hopeless
msix29
(msix29)
July 11, 2022, 9:42pm
#19
I gtg sleep now, i have an idea although it will take a bit of coding, replace the { with a special character and the } with another using string.gsub and when encoding do {encodedthing} and remove them at the end, complicated, when i wake up I’ll try to make it if you didnt understand me, which u obviously didnt with this explanation lol
1 Like
astraIboy
(The Batman)
July 11, 2022, 9:43pm
#20
Thank you so much for all your time and you help, hopefully we can fix it soon
1 Like