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

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)
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 — 6y
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 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
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)


Ad

Answer this question