I made a script to make the desk fall. I make it in the script to do unAnchor, but it doesn’t work. Below I attach a video, screenshot, script. (server and local)
change this part to this
for _, obj in ipairs(Object:GetDescendants()) do
if v:IsA("BasePart") then
v.Anchored = false
end
end
i checked for basepart instead of meshpart, because basepart includes meshpart and all the other parts with Anchored properties
i also changed to getDescendants because the part could be 2 levels down instead of just 1
Still doesn’t work script on the unAnchored
also add if Object:IsA("BasePart") then Object.Anchored = false end
afterwards
Can you show us what is in the tool.Handle from the explorer?
Try also to :SetNetworkOwner() in the end after you unanchor the parts.
You forgot to change v to obj in two lines
^ This will work, he just forgot to change v.
for _, obj in ipairs(Object:GetDescendants()) do
if obj:IsA("BasePart") then
obj.Anchored = false
end
end
Also the reason why you would use ipairs
instead of pairs
is because when dealing with: GetChildren()
and GetDescendants()
, it returns an array.
Usually you can use both ipairs and pairs interchangeably but in situtations where you have an array, you should use ipairs since it’s meant to iterates arrays, pairs will not iterate through a native array, pairs iterates through named dictionaries.
Ex:
Uses pairs
:
local iterableDictionary = {
["Lua"] = {fast = true},
["XML"] = {fast = false}
}
for index: string, language: {fast: boolean} in pairs(iterableDictionary) do
print(language.fast) --(Won't actually be ordered) true, false
end
-- Index will return the index of the entry: "Lua" + "XML"
Uses ipairs
:
local iterableArray = {"Lua", "XML"}
for index : number, language: string in ipairs(iterableArray) do
print(language) -- Returns by order the array entry, "Lua", "XML"
end
-- Index will return the index of the entry: [1], [2]
local iterableArray = {"Lua", "XML"}
local iterableDictionary = {
["Lua"] = {fast = true},
["XML"] = {fast = false}
}
for index : number, language: string in (iterableArray) do --works for both iterableArray / iterableDictionary
print(language) -- Returns by order the array entry, "Lua", "XML"
end
This should do it for you.
???, That’s not how that works??
They introduced that in May 2022 and it’s called generalized iteration.
Well, frankly I never knew they changed that. After some quick research, yes you can use in {...} do
, But it’s only useable in LuaU, natively in Lua you are required to user pairs/ipairs/ or an iterator.
I never got that announcement, I started programming and learning Luau about late 2019, and by the time of this announcement I had already learned iteration and loops quite a while before, so I never paid attention to this. We learn something new every day
Yeah I know I have been using ipairs
and pairs
for so long then once I knew about this new feature for Luau it became like Python just basic in
can do it, and you don’t have to worry about the pairs.
Yea, I mean ultimately it’s a good thing but at the same time it narrows the specificity of Roblox Lua, it used to be that LuaU was basically just a library of lua with extra pre made classes and data models, but when they change the syntax in this kind of way, I feel like it kind of changes the ability for it to be just a Library, it might as well be declared as a entire framework if not another language derived from Lua.
Lol I agree, even someone in the comments said, “I love how Lua is becoming more like JavaScript day-by-day.” I think they just want to make it easier for new programmers and avoid confusion when possible.
I think you should try to unanchor the “Object” instead of every objects in the “Object”
The main issue is that your for loop has no wait,
I have this occurence too where if i have a for loop without wait(). It will not work and it will just think that that is the part
Solution:
Add a task.wait(0.2) to your for loop
Thanks for your comments, I’ll check it out a little later and let you know.
It clones, but it’s as if something is anchoring it again, although I don’t have scripts that do this. Try this model yourself, maybe it won’t work out for you?
Amm.rbxm (25,8 КБ)