Why doesnt this work?

basically trying to have a gui appear when a mouse enters a gui and made this

local hoverinv = script.Parent.Parent.HoverInfo
local mouse = player:GetMouse()

K.MouseEnter:Connect(function()
	hoverinv.Visible = true
	repeat
		hoverinv.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
	until K.MouseLeave
end)

K.MouseLeave:Connect(function()
	hoverinv.Visible = false
end)

its position doesnt update with the mouse & it doesnt appear when the mouse enters the gui

2 Likes

Try replacing:

repeat
    hoverinv.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
until K.MouseLeave

with:

repeat
    hoverinv.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
    task.wait()
until K.MouseLeave

Tell me if that works or not.

Edit: If that doesn’t work try this:

local hoverinv = script.Parent.Parent.HoverInfo
local mouse = player:GetMouse()

local connection

K.MouseEnter:Connect(function()
	hoverinv.Visible = true
	connection = mouse.Move:Connect(function()
		hoverinv.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
	end)
end)

K.MouseLeave:Connect(function()
	hoverinv.Visible = false
	if (connection) then
		connection:Disconnect()
	end
end)

It creates a connection and detects when the players mouse moves and once the mouse leaves the ‘area’ it will disconnect the connection.

2 Likes

Alright so i tried the top one, and it only moved the position once (when the mouse first entered the gui)
The second one for some reason doesnt move the postion whatsoever,

also dont really know whats happening here but no matter what i do
image
The gui just doesnt exist
image
it is visible

1 Like

May I see your entire script setup for this?

Heres the script when for when i was trying the first one (edit, no longer moves it aswell for some reason)

local player = game.Players.LocalPlayer

local hoverinv = script.Parent.Parent.Parent.HoverInfo
local mouse = player:GetMouse()

local K = script.Parent

K.MouseEnter:Connect(function()
	hoverinv.Visible = true
	repeat
		hoverinv.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
		task.wait()
	until K.MouseLeave
end)

K.MouseLeave:Connect(function()
	hoverinv.Visible = false
end)

And heres the second one

local player = game.Players.LocalPlayer

local hoverinv = script.Parent.Parent.Parent.HoverInfo
local mouse = player:GetMouse()

local connection
local K = script.Parent

K.MouseEnter:Connect(function()
	hoverinv.Visible = true
	connection = mouse.Move:Connect(function()
		hoverinv.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
	end)
end)

K.MouseLeave:Connect(function()
	hoverinv.Visible = false
	if (connection) then
		connection:Disconnect()
	end
end)
1 Like

Alright try this:

local frame = script.Parent:WaitForChild("Frame")
local textButton = script.Parent:WaitForChild("TextButton")

local mouse = game.Players.LocalPlayer:GetMouse()

local connection

textButton.MouseEnter:Connect(function()
	frame.Visible = true
	connection = mouse.Move:Connect(function()
		frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
	end)
end)

textButton.MouseLeave:Connect(function()
	frame.Visible = false
	if (connection) then
		connection:Disconnect()
	end
end)

It’s the same ish as the second one but the issue was with the Udim2.

Edit: Make sure to edit the names in the script.

1 Like

Alright this worked!
2022-05-02-15-53-15-online-video

Although one more question, whenever i go fast through the guis This happens
2022-05-02-15-53-22-online-video
Sometimes the gui doesnt appear, it isnt a big issue although im just wondering if theres a fix to this or am i stuck with it

1 Like

I could be wrong but this might be an issue with roblox (aka .MouseEnter event)
I’ll take a look anyway give me a second.

1 Like

Try this:

local frame = script.Parent:WaitForChild("Frame")
local textButton = script.Parent:WaitForChild("TextButton")

local mouse = game.Players.LocalPlayer:GetMouse()

frame:SetAttribute("AmountSelectedBy",0)

for index,item in pairs(script.Parent:WaitForChild("ScrollingFrame"):GetChildren()) do
	if (item:IsA("TextButton")) then
		item.MouseEnter:Connect(function()
			frame.Visible = true
			frame:SetAttribute("AmountSelectedBy",frame:GetAttribute("AmountSelectedBy")+1)
		end)
		
		item.MouseLeave:Connect(function()
			frame:SetAttribute("AmountSelectedBy",frame:GetAttribute("AmountSelectedBy")-1)
			if (frame:GetAttribute("AmountSelectedBy") == 0) then
				frame.Visible = false
			end
		end)
	end
end

mouse.Move:Connect(function()
	frame.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end)
1 Like

ill try it out in a bit, although is there a way to get the code to work in this function

for i, v in ipairs(CurrentInv) do
	local K = C:Clone()
	K.Text = v.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(v)
		K:Destroy()
	end)
	
	K.MouseEnter:Connect(function()
		connection = mouse.Move:Connect(function()
			hoverinv.Position = UDim2.new(0,mouse.X,0,mouse.Y)
		end)
	end)
	
	K.MouseLeave:Connect(function()
		hoverinv.Visible = false
		if (connection) then
			connection:Disconnect()
		end
	end)
end

i tried pasting it over, and it doesnt really work

1 Like

May I see the entire script? I’m not sure what C is equal to.

local player = game.Players.LocalPlayer
local inv = game.ReplicatedStorage.PlayerInvetorys:WaitForChild(player.Name .. "Folder")
local CurrentInv = inv:GetChildren()
local C = script.Parent.ItemFrame
local hoverinv = script.Parent.Parent.HoverInfo
local mouse = player:GetMouse()
local connection

print(CurrentInv)

function equipitem(item)
	if not item then warn("Wheres My Gun At?") return end
	game.ReplicatedStorage.TotallyCoolEvents.EquipGun:FireServer(item)
end

for i, v in ipairs(CurrentInv) do
	local K = C:Clone()
	K.Text = v.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(v)
		K:Destroy()
	end)
	
	K.MouseEnter:Connect(function()
		connection = mouse.Move:Connect(function()
			hoverinv.Position = UDim2.new(0,mouse.X,0,mouse.Y)
		end)
	end)
	
	K.MouseLeave:Connect(function()
		hoverinv.Visible = false
		if (connection) then
			connection:Disconnect()
		end
	end)
end

inv.ChildAdded:Connect(function(Child)
	local K = C:Clone()
	K.Text = Child.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(Child)
		K:Destroy()
	end)
end)
1 Like

Try This:

local player = game.Players.LocalPlayer
local inv = game.ReplicatedStorage.PlayerInvetorys:WaitForChild(player.Name .. "Folder")
local CurrentInv = inv:GetChildren()
local C = script.Parent.ItemFrame
local hoverinv = script.Parent.Parent.HoverInfo
local mouse = player:GetMouse()

print(CurrentInv)

hoverinv:SetAttribute("AmountSelectedBy",0)

function equipitem(item)
	if not item then warn("Wheres My Gun At?") return end
	game.ReplicatedStorage.TotallyCoolEvents.EquipGun:FireServer(item)
end

for i, v in ipairs(CurrentInv) do
	local K = C:Clone()
	K.Text = v.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(v)
		K:Destroy()
	end)

	K.MouseEnter:Connect(function()
		hoverinv.Visible = true
		hoverinv:SetAttribute("AmountSelectedBy",hoverinv:GetAttribute("AmountSelectedBy")+1)
	end)

	K.MouseLeave:Connect(function()
		hoverinv:SetAttribute("AmountSelectedBy",hoverinv:GetAttribute("AmountSelectedBy")-1)
		if (hoverinv:GetAttribute("AmountSelectedBy") == 0) then
			hoverinv.Visible = false
		end
	end)
end

inv.ChildAdded:Connect(function(Child)
	local K = C:Clone()
	K.Text = Child.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(Child)
		K:Destroy()
	end)
end)

mouse.Move:Connect(function()
	hoverinv.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end)

i tried it and the hover gui didnt appear

1 Like

May I see what happens when you hover over the guns?


^with hover gui visibility pre disabled

^with hover gui visibility pre enabled

1 Like

Try this:

local player = game.Players.LocalPlayer
local inv = game.ReplicatedStorage.PlayerInvetorys:WaitForChild(player.Name .. "Folder")
local CurrentInv = inv:GetChildren()
local C = script.Parent.ItemFrame
local hoverinv = script.Parent.Parent.HoverInfo
local mouse = player:GetMouse()

print(CurrentInv)

hoverinv:SetAttribute("AmountSelectedBy",0)

function equipitem(item)
	if not item then warn("Wheres My Gun At?") return end
	game.ReplicatedStorage.TotallyCoolEvents.EquipGun:FireServer(item)
end

for i, v in ipairs(CurrentInv) do
	local K = C:Clone()
	K.Text = v.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(v)
		K:Destroy()
	end)

	K.MouseEnter:Connect(function()
		hoverinv.Visible = true
		hoverinv:SetAttribute("AmountSelectedBy",hoverinv:GetAttribute("AmountSelectedBy")+1)
	end)

	K.MouseLeave:Connect(function()
		hoverinv:SetAttribute("AmountSelectedBy",hoverinv:GetAttribute("AmountSelectedBy")-1)
		if (hoverinv:GetAttribute("AmountSelectedBy") == 0) then
			hoverinv.Visible = false
		end
	end)
end

inv.ChildAdded:Connect(function(Child)
	local K = C:Clone()
	K.Text = Child.Name
	K.Visible = true
	K.Parent = C.Parent
	K.MouseButton1Click:Connect(function()
		equipitem(Child)
		K:Destroy()
	end)
	
	K.MouseEnter:Connect(function()
		hoverinv.Visible = true
		hoverinv:SetAttribute("AmountSelectedBy",hoverinv:GetAttribute("AmountSelectedBy")+1)
	end)

	K.MouseLeave:Connect(function()
		hoverinv:SetAttribute("AmountSelectedBy",hoverinv:GetAttribute("AmountSelectedBy")-1)
		if (hoverinv:GetAttribute("AmountSelectedBy") == 0) then
			hoverinv.Visible = false
		end
	end)
end)

mouse.Move:Connect(function()
	hoverinv.Position = UDim2.new(0,mouse.X,0,mouse.Y)
end)

this does work, althought it still has the same problem with the other script, where if you move too fast it doesnt show up

1 Like

May I see a screenshot of your user interface? e.g:
image

image

1 Like