This is in a local script. What am I trying to achieve here is to make the items in the 'Tags' table to be shown on a UI when your mouse is hovered on said object. Let's say I made 2 door models in the doors folder, with 2 tools on the tools folder. I used this local script in the StarterGui. It worked for the 2nd door and tool but not for the 1st door and tool. It only shows the last item on the table when you hover on it, but it doesn't work for other objects. I hope you get my problem...
--StackEdit added an extra space per line...
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local Tools = game.Workspace.tools:GetChildren() -- Get the tools in the tools folder.
local Doors = game.Workspace.doors:GetChildren() -- Get the doors in the doors folder.
local gui = player.PlayerGui:WaitForChild("toolGui")
local label = gui.Label
local Tags = {}
--Putting everything in the Tags table.
for i,v in pairs (Tools) do
table.insert(Tags, v)
wait()
end
for i,v in pairs (Doors) do
table.insert(Tags, v)
wait()
end
--Defining the thing for Tags per class
for i,v in pairs (Tags) do
if v:IsA("Tool") then
toolName = v.Name
toolDetect = v:WaitForChild("ClickDetector") -- Assuming it's already there...
end
end
for i,v in pairs (Tags) do
if v:IsA("Model") then
doorName = v.Name
doorDetect = v.Door:WaitForChild("ClickDetector") -- Assuming it's already there...
end
end
--The problem here is that these parts only call the name of the last item per class in the Tags table.
toolDetect.MouseHoverEnter:connect(function(t)
label.Text = toolName
label.Visible = true
mouse.Icon = 'rbxassetid://120192974'
end)
toolDetect.MouseHoverLeave:Connect(function()
mouse.Icon = 'rbxassetid://120192974'
label.Visible = false
label.Text = "Label"
end)
doorDetect.MouseHoverEnter:connect(function(d)
label.Text = doorName
label.Visible = true
mouse.Icon = 'rbxassetid://120192974'
end)
doorDetect.MouseHoverLeave:Connect(function()
mouse.Icon = 'rbxassetid://120192974'
label.Visible = false
label.Text = "Label"
end)

2 comments
Ok thanks.
no problem