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

How do i make this ''crate'' go back to normal once it's function is actually done in the game?

Asked by
ali7682 17
7 years ago

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

01b = script.Parent
02script.Parent.Humanoid.HealthChanged:connect(function()
03if script.Parent.Humanoid.Health <= 0 then
04b.Center.Transparency = 1
05b.Center.CanCollide = false
06b.Part1.Anchored = false
07b.Part2.Anchored = false
08b.Part3.Anchored = false
09b.Part4.Anchored = false
10b.Part5.Anchored = false
11b.Part6.Anchored = false
12b.Part7.Anchored = false
13b.Part8.Anchored = false
14b.Part9.Anchored = false
15b.Part10.Anchored = false
View all 25 lines...
0
I don't quite understand. So the crate's center remains but is invisible, the rest of the parts get unanchored, so they drop to the floor correct? are you wanting the script to then put all the parts back in the place they was before the crate's health was 0? FrozenWinterz 50 — 7y
0
I want all the parts to get back to how they were when the health = 0 or lower. And yes the parts will be all unanchored (so they will fall on the ground) except for the part that's called ''center''. That part will be invisible and uncancollide then. ali7682 17 — 7y

1 answer

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago
01b = script.Parent
02function resetposition()
03for i=1,18,1 do
04b.Part[i].Anchored=true
05b.Part[i].Position=positions[i]
06end
07end
08--Set up a resetposition function, you can call that whenever you want to reset their positions by simply typing: resetposition() in this script.
09script.Parent.Humanoid.HealthChanged:connect(function()
10if script.Parent.Humanoid.Health <= 0 then
11positions={b.Part1.Position,b.Part2.Position,b.Part3.Position,b.Part4.Position,b.Part5.Position,b.Part6.Position,b.Part7.Position,b.Part8.Position,
12b.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,}
13b.Center.Transparency = 1
14b.Center.CanCollide = false
15b.Part1.Anchored = false
View all 34 lines...
Ad

Answer this question