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

How do I find when a block has fallen on its side?

Asked by
Kitorari 266 Moderation Voter
8 years ago

Lets say you have a pin, and it falls over, I'm trying to get the information that it has "fallen over" to a score board.

How do I do that? Rotation/positioning? I'm dumb-founded.

Any assistance would be great!

What I got so far:

1If ((Insert information here)) true then
2do
3Workspace.PartScoreboard.Surfacegui.Frame.Pin1.color3.new  = Color3((0, 0, 1,))
4end

1 answer

Log in to vote
1
Answered by 8 years ago

I'm sure there's some brilliant, efficient, mathematical solution to this problem but because I'm not brilliant and good with math, the way I'd do it is maybe have a transparent part surrounding the top of the object and then detect whether or not it touches the floor. And then running your desired code if it does hit the floor.

Example:

1local enabled = true
2 
3script.Parent.Sensor.Touched:connect(function(hit)
4    if hit.Name == "Floor" and enabled then
5        enabled = false
6        print("Pin has hit the floor, running code.")
7    end
8end)

I tried this out in studio and it worked perfectly fine. I also tried another method with checking whenever the axis's of the desired object got below or above a certain degree and then running the script. But sadly the .Changed event does not work with rotation if the part is not anchored. However you might shine some light on that method yourself.

Ad

Answer this question