Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to detect which side of a cube is up?

ive already tried a code from devforum, but it doesnt work, so how do i detect what side of a cube is up?

the code btw:

function findSide(part)
     local cf=part.CFrame
     local cs={side=nil,y=-2}
     if cf.lookVector.Y>cs.y then cs.side="FrontSurface" cs.y=cf.lookVector.Y end
     if -cf.lookVector.Y>cs.y then cs.side="BackSurface" cs.y=-cf.lookVector.Y end
     if cf.rightVector.Y>cs.y then cs.side="RightSurface" cs.y=cf.rightVector.Y end
     if -cf.rightVector.Y>cs.y then cs.side="LeftSurface" cs.y=-cf.rightVector.Y end
     if cf.upVector.Y>cs.y then cs.side="TopSurface" cs.y=cf.upVector.Y end
     if -cf.upVector.Y>cs.y then cs.side="BottomSurface" cs.y=-cf.upVector.Y end
     return script.Parent.numdisplay.TextLabel.Text
end

Im trying to change a textlabels text to the side that the cube is on, but nothing is changing.

1 answer

✓ Accepted answer
function findSide(part)
     local cf=part.CFrame
     local cs={side=nil,y=-2}
     if cf.lookVector.Y>cs.y then cs.side="1" cs.y=cf.lookVector.Y end --FrontSurface
     if -cf.lookVector.Y>cs.y then cs.side="2" cs.y=-cf.lookVector.Y end --BackSurface
     if cf.rightVector.Y>cs.y then cs.side="3" cs.y=cf.rightVector.Y end --RightSurface
     if -cf.rightVector.Y>cs.y then cs.side="4" cs.y=-cf.rightVector.Y end --LeftSurface
     if cf.upVector.Y>cs.y then cs.side="5" cs.y=cf.upVector.Y end --TopSurface
     if -cf.upVector.Y>cs.y then cs.side="6" cs.y=-cf.upVector.Y end --BottomSurface
     return cs.side --Return the function as the side number
end

while wait() do
script.Parent.numdisplay.TextLabel.Text = findSide(script.Parent) --Since you returned cs.side, "findSide" is now a string and you can use it for the text label
end

This should work. It wasn't working because you were returning the text of the textlabel and not doing anything about it.

3 comments

0

ok cool, is there a way to make it change if the side of the cube changes? also, is there a way to number the surfaces and display the number?

0

Make it change what exactly ? And yes there is a way to number the surfaces.

0

so if i move the cube and then the right surface is up, it should say rightsurface

This discussion is preserved as it was. New answers, comments, and votes are closed.