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
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
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!
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