How do you get a decimal for magnitude

Hi!

So um i made a Waypoint marker that tracks the Player’s PrimaryPart to the Waypoint, I rounded the number and got a whole number, but i was wondering, how to i get a tenth to appear alongside the number

Script: (Sorry for the weird Variable names, i was changing the paths)

Completed = false

while wait() do
PlayersPrimaryPartPos = game.Players.LocalPlayer.Character.PrimaryPart
PartPos = workspace.Waypoints_Marker:FindFirstChild("WayPoint1")
local Magnitude = (PlayersPrimaryPartPos.Position - PartPos.Position).Magnitude	
	PartPos.BillboardGui.PositionLength.Text = math.ceil(Magnitude).."m"
	if (PlayersPrimaryPartPos.Position - PartPos.Position).Magnitude <= 5 then	
		Completed = not Completed
		PartPos.Sound:Play()
		PartPos.BillboardGui.ExtentsOffsetWorldSpace = Vector3.new(0,-5,0)
		PartPos.BillboardGui.PositionLength.Text = ""
		PartPos.BillboardGui.Pointer.Size = UDim2.new(1,0,1,0)
		PartPos.BillboardGui.Pointer.Text = "✅"
		break
	end
end
for i = 1,100 do
	wait()
	PartPos.Transparency += 0.01
end
PartPos:Destroy()


To make myself more clear, i want a decimal, so like 13.7 or something.
Anything helps.

You can use PartPos.BillboardGui.PositionLength.Text = math.ceil(Magnitude * 10)/10

Try this:

--//Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local PrimaryPart = Character.PrimaryPart
local Waypoint = workspace.Waypoints_Marker:WaitForChild("WayPoint1")

--//Functions
local function roundNumber(number)
	return tonumber(string.format("%.1f", number))
end

while task.wait() do
	local Magnitude = (PrimaryPart.Position - Waypoint.Position).Magnitude	
	Waypoint.BillboardGui.PositionLength.Text = roundNumber(Magnitude) .."m"
	
	if Magnitude <= 5 then			
		Waypoint.Sound:Play()
		Waypoint.BillboardGui.ExtentsOffsetWorldSpace = Vector3.new(0, -5, 0)
		Waypoint.BillboardGui.PositionLength.Text = ""
		Waypoint.BillboardGui.Pointer.Size = UDim2.new(1, 0, 1,0)
		Waypoint.BillboardGui.Pointer.Text = "✅"
		
		break
	end
end

local transparencyTween = TweenService:Create(Waypoint, TweenInfo.new(1, Enum.EasingStyle.Quint), {Transparency = 1})
transparencyTween:Play()
transparencyTween.Completed:Wait()

Waypoint:Destroy()

I tested this out, i am now recieving errors from the text.

Players.xGOA7x.PlayerGui.LocalScript:17: attempt to index nil with 'Position'

Try this:

--//Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local PrimaryPart = Character.PrimaryPart
local Waypoint = workspace.Waypoints_Marker:WaitForChild("WayPoint1")

--//Functions
local function roundNumber(number)
	return tonumber(string.format("%.1f", number))
end

while task.wait() do
	PrimaryPart = Character.PrimaryPart
	
	local Magnitude = (PrimaryPart.Position - Waypoint.Position).Magnitude	
	Waypoint.BillboardGui.PositionLength.Text = roundNumber(Magnitude) .."m"

	if Magnitude <= 5 then			
		Waypoint.Sound:Play()
		Waypoint.BillboardGui.ExtentsOffsetWorldSpace = Vector3.new(0, -5, 0)
		Waypoint.BillboardGui.PositionLength.Text = ""
		Waypoint.BillboardGui.Pointer.Size = UDim2.new(1, 0, 1,0)
		Waypoint.BillboardGui.Pointer.Text = "✅"

		break
	end
end

local transparencyTween = TweenService:Create(Waypoint, TweenInfo.new(1, Enum.EasingStyle.Quint), {Transparency = 1})
transparencyTween:Play()
transparencyTween.Completed:Wait()

Waypoint:Destroy()

@Katrist
Still getting the same from here

Where is the LocalScript located?

Also, try this:

--//Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local PrimaryPart = Character:WaitForChild("HumanoidRootPart")
local Waypoint = workspace.Waypoints_Marker:WaitForChild("WayPoint1")

--//Functions
local function roundNumber(number)
	return tonumber(string.format("%.1f", number))
end

while task.wait() do
	local Magnitude = (PrimaryPart.Position - Waypoint.Position).Magnitude	
	Waypoint.BillboardGui.PositionLength.Text = roundNumber(Magnitude) .."m"

	if Magnitude <= 5 then			
		Waypoint.Sound:Play()
		Waypoint.BillboardGui.ExtentsOffsetWorldSpace = Vector3.new(0, -5, 0)
		Waypoint.BillboardGui.PositionLength.Text = ""
		Waypoint.BillboardGui.Pointer.Size = UDim2.new(1, 0, 1,0)
		Waypoint.BillboardGui.Pointer.Text = "✅"

		break
	end
end

local transparencyTween = TweenService:Create(Waypoint, TweenInfo.new(1, Enum.EasingStyle.Quint), {Transparency = 1})
transparencyTween:Play()
transparencyTween.Completed:Wait()

Waypoint:Destroy()

the LocalScript is located in StarterGui

Also about this:

if Magnitude <= 5 then			
		Waypoint.Sound:Play()
		Waypoint.BillboardGui.ExtentsOffsetWorldSpace = Vector3.new(0, -5, 0)
		Waypoint.BillboardGui.PositionLength.Text = ""
		Waypoint.BillboardGui.Pointer.Size = UDim2.new(1, 0, 1,0)
		Waypoint.BillboardGui.Pointer.Text = "✅"

		break
	end

This part of the script sets the BillboardGui to the center of part so the Check mark can be in the center.

Ohh, the video didn’t load before I made my post. The only reason the numbers are flickering is because it reached exactly a whole number, which is why no decimal points were shown.

Yeah, i noticed that, is there a way for you to get a .0 when getting a whole number?

Yes, try this:

--//Services
local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")

--//Variables
local LocalPlayer = Players.LocalPlayer
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local PrimaryPart = Character.PrimaryPart
local Waypoint = workspace.Waypoints_Marker:WaitForChild("WayPoint1")

--//Functions
local function roundNumber(number)
	return tonumber(string.format("%.1f", number))
end

while task.wait() do
	PrimaryPart = Character.PrimaryPart

	local Magnitude = (PrimaryPart.Position - Waypoint.Position).Magnitude	
	local roundedNumber = roundNumber(Magnitude)
	
	if roundedNumber % 1 == 0 then
		roundedNumber = tostring(roundedNumber.. ".0")
	end
	
	Waypoint.BillboardGui.PositionLength.Text = roundedNumber .."m"

	if Magnitude <= 5 then			
		Waypoint.Sound:Play()
		Waypoint.BillboardGui.ExtentsOffsetWorldSpace = Vector3.yAxis * -5
		Waypoint.BillboardGui.PositionLength.Text = ""
		Waypoint.BillboardGui.Pointer.Size = UDim2.fromScale(1, 1)
		Waypoint.BillboardGui.Pointer.Text = "✅"

		break
	end
end

local transparencyTween = TweenService:Create(Waypoint, TweenInfo.new(1, Enum.EasingStyle.Quint), {Transparency = 1})
transparencyTween:Play()
transparencyTween.Completed:Wait()

Waypoint:Destroy()

Thank you so much, I wasn’t sure know how to use modulo.

1 Like

No problem. If you have any more questions, feel free to ask.