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