Hi, i've made model and inside that model there is a crate with some parts in it that make the crate (18 parts) and a humanoid (stats are Maxhealth = 100, Health = 100) and a script. So the idea is, if the crate's health goes to 0 or lower the parts (17 parts) will get unanchored, leaving 1 part and that's called the ''center''. That part will be transparent and uncancollide. Now what the problem is, is that i can't find a way to redo that. So if the parts get unanchored and the center goes transparent and uncancollide, it won't return later back to normal how it was. Can someone help me? Here is the script. Oh, i just started scripting so there might be some things i did in the script that are stupid and could be written shorter or something. If you could teach me a way to do that it would be awesome! Thanks :D
b = script.Parent script.Parent.Humanoid.HealthChanged:connect(function() if script.Parent.Humanoid.Health <= 0 then b.Center.Transparency = 1 b.Center.CanCollide = false b.Part1.Anchored = false b.Part2.Anchored = false b.Part3.Anchored = false b.Part4.Anchored = false b.Part5.Anchored = false b.Part6.Anchored = false b.Part7.Anchored = false b.Part8.Anchored = false b.Part9.Anchored = false b.Part10.Anchored = false b.Part11.Anchored = false b.Part12.Anchored = false b.Part13.Anchored = false b.Part14.Anchored = false b.Part15.Anchored = false b.Part16.Anchored = false b.Part17.Anchored = false b.Part18.Anchored = false end end)
b = script.Parent function resetposition() for i=1,18,1 do b.Part[i].Anchored=true b.Part[i].Position=positions[i] end end --Set up a resetposition function, you can call that whenever you want to reset their positions by simply typing: resetposition() in this script. script.Parent.Humanoid.HealthChanged:connect(function() if script.Parent.Humanoid.Health <= 0 then positions={b.Part1.Position,b.Part2.Position,b.Part3.Position,b.Part4.Position,b.Part5.Position,b.Part6.Position,b.Part7.Position,b.Part8.Position, b.Part9.Position,b.Part10.Position,b.Part11.Position,b.Part12.Position,b.Part13.Position,b.Part14.Position,b.Part15.Position,b.Part16.Position,b.Part17.Position,} b.Center.Transparency = 1 b.Center.CanCollide = false b.Part1.Anchored = false b.Part2.Anchored = false b.Part3.Anchored = false b.Part4.Anchored = false b.Part5.Anchored = false b.Part6.Anchored = false b.Part7.Anchored = false b.Part8.Anchored = false b.Part9.Anchored = false b.Part10.Anchored = false b.Part11.Anchored = false b.Part12.Anchored = false b.Part13.Anchored = false b.Part14.Anchored = false b.Part15.Anchored = false b.Part16.Anchored = false b.Part17.Anchored = false b.Part18.Anchored = false end end)