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

How do i fix my magnittude that is linked to the player head?

I have a MouseoverText LocalScript, its basically a textlabel that follows the mouse when it points to a part, I made a magnitude for it so you will only see it when youre near it,but its not working, please help me ty

the part 1 of the magnitude is the player head since its a first person game and the part 2 is the mouse target

script:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local label = script.Parent
local target = mouse.Target
local range = 10
local head = player.Character:WaitForChild("Head")

function updatePos ()

	local X = mouse.X
	local Y = mouse.Y
	
	if target and target:FindFirstChild("MouseoverText") and (head.Position - target.Position).magnitude <= range then
		label.Position = UDim2.new(0.01,X,0.01,Y)
		label.Text = target.MouseoverText.Value
		label.Visible = true
	else
		label.Visible = false
	end
end

mouse.Move:Connect(updatePos)

updatePos()

1 answer

✓ Accepted answer
  1. It's .Magnitude with capital M

  2. You want to update your target variable since it only assign mouse's target at run time, and then never again i suggest you move that varible into the updatePos() function

1 comment

0

.magnitude also works. Capitalization doesn’t matter.

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