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

How can I get my mouse hover script to create a gui at the mouse position?

I've attempted to make a script that displays a gui when it hovers over an object with a Humanoid in it and the instance called Hover inside the object.

Nothing happens...please help.

Player = game.Players.LocalPlayer
Mouse = Player:GetMouse()

while wait() do
	if Mouse.Target then
		print(1)
		if Mouse.Target:FindFirstChild("Humanoid") and Mouse.Target ~= Player.Character then
			print(2)
			if Mouse.Target:FindFirstChild("Hover") then
				HoverWords = Instance.new("TextLabel", Player.PlayerGui.ScreenGui)
				HoverWords.BackgroundTransparency = 0.4
				HoverWords.BackgroundColor3 = Color3.new(0, 0, 0)
				HoverWords.BorderColor3 = Color3.new(255, 255, 255)
				HoverWords.Size = UDim2.new(0.075, 0, 0.035, 0)
				HoverWords.TextColor3 = Color3.new(255, 255, 255)
				HoverWords.Text = Mouse.Target.Torso:FindFirstChild("Hover").Value
				HoverWords.Position = UDim2.new(Mouse.X, 0, Mouse.Y, 0)
			end
		end
	end
end

1 answer

✓ Accepted answer

The problem is that you are setting the scale of your GUI to Mouse.X/Mouse.Y, which are offsets. To fix this:

-- Line 17:
HoverWords.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)

Another problem is when you check to see if there is a humanoid inside the model. Since Mouse.Target is a part, and the humanoid is in the model, I'd do this:

if Mouse.Target.Parent:FindFirstChild("Humanoid") and Mouse.Target.Parent ~= player.Character ...

I would also recommend using the Move event rather than a loop, like this:

Mouse.Move:connect(function()
	-- The rest of the code here.
end

Finally, you create a new label every time the loop runs. I would create one label in the StarterGui, then re-use that same label.

3 comments

0

Nah didn't change anything, it only gets as far as the first print.

0

I added more information which should help.

0

Thank you it works now!

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