The GUI will only pop up if the item the mouse hovers over is at the bottom of the 'items' table. Script:
local plr = game.Players.LocalPlayer repeat wait() until plr.Character local char = plr.Character local mouse = plr:GetMouse() local items = { "cup", "metal scraps", "bottlecap", } while wait() do if mouse.Target ~= nil then for _,v in pairs(items) do if mouse.Target.Name:lower() == v then script.Parent.Visible = true script.Parent.Text = "[ Press 'E' to pick up "..mouse.Target.Name.." ]" else script.Parent.Visible = false end end end end
It will work if my mouse hovers over an item named "Bottlecap", but if I hover over an item named "Metal Scraps", it won't. Help?
There's something subtle about your code. Let's step through it for "bottlecap" first:
1.a. if target is "cup" then
1.b. (it's not)
1.c. else
1.d. hide gui
2.a. if target is "metal scraps" then
2.b. (it's not)
2.c. else
2.d. hide gui
3.a. if target is "bottlecap" then
3.b. show "pick up " .. "Bottlecap"
3.c. else
3.d. (it was)
Now compare this to running through with "metal scraps"
1.a. if target is "cup" then
1.b. (it's not)
1.c. else
1.d. hide gui
2.a. if target is "metal scraps" then
2.b. show "pick up " .. "Metal Scraps"
2.c. else
2.d. (it was)
3.a. if target is "bottlecap" then
3.b. (it's not)
3.c. else
3.d. (hide gui)
Notice the problem? For each name, you take a definitive action -- either show or hide -- thus the only one that ends up mattering is the last one.
You only want to make it invisible when none match.
A simple way to accomplish that is start by hiding it, then just show it when you put text:
Also, tab your code properly!
while wait() do if mouse.Target ~= nil then script.Parent.Visible = false for _,v in pairs(items) do if mouse.Target.Name:lower() == v then script.Parent.Visible = true script.Parent.Text = "[ Press 'E' to pick up "..mouse.Target.Name.." ]" end end end end
Read comment
local plr = game.Players.LocalPlayer repeat wait() until plr.Character local char = plr.Character local mouse = plr:GetMouse() local items = { "cup", "metal scraps", "bottlecap", } while wait() do if mouse.Target ~= nil then for _,v in pairs(items[1, 2, 3]) do --I hope this works. Try to get all items in the table named "items" if mouse.Target.Name:lower() == v then script.Parent.Visible = true script.Parent.Text = "[ Press 'E' to pick up "..mouse.Target.Name.." ]" else script.Parent.Visible = false end end end end
I hope this helps