Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I make all parts of a model unanchored?

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

6 comments

0

Did you add something to trigger the function?

0

I removed the unnecessary game.Workspace.house:GetChildren() in the function but still nothing

0

@JustinWe12 I added the onTouch function or I am forgetting to connect the function or something with tables

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.

0

You didn't call the fuction

0

But the answers below say I called it? How can I correct this

3 answers

✓ Accepted answer

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

2 comments

0

Its .Touched with an ed in the back

0

Didnt work

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!

3 comments

0

I knew i was forgetting that, but oddly enough it didnt work

0

Yes I put an answer with it

0

Can U help me pls I did not work

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

This discussion is preserved as it was. New answers, comments, and votes are closed.