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

Why does this not work?

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" :/

3 comments

0

Your script must be in a local script.

0

It is a local script, inside a gui ,located in startergui

0

Please explain what you're trying to accomplish and make your question title relevant to the content.

1 answer

✓ Accepted answer
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)

1 comment

0

Thank you!

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