Hi Guys, it is the first time ever I even saw Code Review, so I don’t know much about is it the right place to post this, but the name only brought me here.
I was trying to make a GUI you must have seen in different games, basically how much far something is from our character. I made a GUI for it. I ain’t much satisfied with my code, so it would be helpful if you help me in my code and give any idea or figure out any problem. Thanks
local hrp = game.Players.LocalPlayer.Character:WaitForChild("HumanoidRootPart")
while wait(0.5) do
local cframe = workspace.Part2.Position.Magnitude
position = UDim2.new(character.Position.Magnitude/cframe)
You are misunderstanding thr concept of ‘magnitude’. What you will need to do is put the HumanoidRootPart’s POSITION into a variable, find the second object amd get the POSITION of it as well. Next, you can get the distance between the character and the target object as shown below:
local HRP = game.Players.LocalPlayer.Character:WaitForChikd("HumanoidRootPart");
local TargetObject = workspace.Object --your second object
local magnitude = (HRP.Position - TargetObject.Position).magnitude
For the rest of the code I’m not sure what you are trying to achieve, but this is the main thing you’ll need.
Basically I want to depict in a GUI how much far the HRP is from the Target. There would be a frame tweening relative to how much far we are from the target. Like when we are at the middle, the frame also gets at the middle, when we reached end, frame also reaches the end.