Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I make all parts of a model unanchored?

Asked by
ym5a 52
2 years ago

I made a script

local parts = workspace.House:GetChildren()

function onTouch(selfdestruct)
    game.Workspace.house:GetChildren()
    for i,v in pairs(parts) do
        v.Anchored = false
    end
end

I dont see any errors in output but nothing happens Please help I am very nooby at Lua roblox

0
Did you add something to trigger the function? JustinWe12 723 — 2y
0
I removed the unnecessary game.Workspace.house:GetChildren() in the function but still nothing ym5a 52 — 2y
0
@JustinWe12 I added the onTouch function or I am forgetting to connect the function or something with tables ym5a 52 — 2y
0
That is just the name of the function. Someone posted and answer, you can see how to properly call the function with touch event. JustinWe12 723 — 2y
View all comments (2 more)
0
You didn't call the fuction MattVSNNL 620 — 2y
0
But the answers below say I called it? How can I correct this ym5a 52 — 2y

3 answers

Log in to vote
0
Answered by
ym5a 52
2 years ago
Edited 2 years ago

I figured it out the 'h' in house was capitalized which should not have been

local parts = game.Workspace.house:GetChildren()
local part = game.Workspace.selfdestruc
function onTouch(part)
    for i,v in pairs(parts) do
        v.Anchored = false
    end
end

part.Touched:Connect(onTouch)

Thanks for helping me guys

0
Its .Touched with an ed in the back JustinWe12 723 — 2y
0
Didnt work ym5a 52 — 2y
Ad
Log in to vote
0
Answered by 2 years ago

You will need to call the function when the part touched

local parts = workspace.House:GetChildren()
local part -- the part you need to be touch
function onTouch(selfdestruct)
--    game.Workspace.house:GetChildren() You won't need this since it doesn't do anything
    for i,v in pairs(parts) do
        v.Anchored = false
    end
end

part.Touch:Connect(onTouch)

or if you want it to work without touching the part

local parts = workspace.House:GetChildren()
function onTouch(selfdestruct)
--    game.Workspace.house:GetChildren() You won't need this since it doesn't do anything
    for i,v in pairs(parts) do
        v.Anchored = false
    end
end

onTouch()

Hope that helped!

0
I knew i was forgetting that, but oddly enough it didnt work ym5a 52 — 2y
0
Yes I put an answer with it ym5a 52 — 2y
0
Can U help me pls I did not work ym5a 52 — 2y
Log in to vote
0
Answered by 2 years ago

You should always check wether or not the Instance is a BasePart & make sure you're not calling functions for pointless reasons. Instance.GetChildren returns a table, it doesn't save it for your next statement/loop.

local OnTouched; OnTouched = function(HitInstance)
    for index, value in pairs(workspace.House:GetChildren()) do
        if value:IsA("BasePart") then
            value.Anchored = false
        end
    end
end

Answer this question