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

Why does this not work?

Asked by
Poine 30
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.
local p = game.Players.LocalPlayer
local mouse = p:GetMouse()
local mP = mouse.Target
local nm = script.Parent.uName.Text
local hp = script.Parent.uHP.Text


mouse.Move:connect(function()
    if mP then
        print "mp"
    if mP.Parent:FindFirstChild("Humanoid") or mP.Parent:FindFirstChild("TowerHumanoid") then
        print(mP.Parent.Name)
        hp = mP.Parent.Humanoid.Health
        nm = mP.Parent.Name
    end end
end)

It doesn't even print "mp" :/

0
Your script must be in a local script. dirty_catheter 7 — 8y
0
It is a local script, inside a gui ,located in startergui Poine 30 — 8y
0
Please explain what you're trying to accomplish and make your question title relevant to the content. M39a9am3R 3210 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago
local nm = script.Parent.uName.Text
local hp = script.Parent.uHP.Text

Here, nm and hp are being set to the value of whatever the text of uName and uHP is.

hp = mP.Parent.Humanoid.Health
nm = mP.Parent.Name

This just changes the string value that hp and nm have, not the text of gui.

nm and hp should instead equal the actual gui instance.

mP is set to the value mouse's target before there is a target and mP is never updated with the new mouse target.

local p = game.Players.LocalPlayer
local mouse = p:GetMouse()
local mP = mouse.Target
--equal gui instance
local nm = script.Parent.uName
local hp = script.Parent.uHP


mouse.Move:connect(function()
    -- update mP
    mP = mouse.Target
    if mP then
        print "mp"
        if mP.Parent:FindFirstChild("Humanoid") or mP.Parent:FindFirstChild("TowerHumanoid") then
        print(mP.Parent.Name)
    --change text of gui instance
        hp.Text = mP.Parent.Humanoid.Health
        nm.Text = mP.Parent.Name
        end 
    end
end)

0
Thank you! Poine 30 — 8y
Ad

Answer this question