Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 2 years ago
Edited 2 years ago

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

Log in to vote
0
Answered by 2 years ago
  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

0
.magnitude also works. Capitalization doesn’t matter. Nckripted 580 — 2y
Ad

Answer this question