Hello there! I have a problem I just can't quite seem to fix and it makes no sense to me.
Full Code
df = script.Parent:WaitForChild("DefaultItem")
items = script.Parent:WaitForChild("Items")
trails = game.ReplicatedStorage:WaitForChild("Trails")
-- df means default
df.Visible = false
CurrentData = script.Parent:WaitForChild("CurrentData", 999)
EquippedItem = CurrentData:WaitForChild("EquippedItem", 999)
OwnedItems = CurrentData:WaitForChild("OwnedItems", 999)
function update()
for i, v in pairs(trails:GetChildren()) do
if not items:FindFirstChild(v.Name) then
local trail = v:FindFirstChild("Trail")
local trailtype = v:FindFirstChild("TrailType")
local icon = v:FindFirstChild("Icon")
local price = v:FindFirstChild("Price")
if trail and trailtype and icon and price then
local clone = df:Clone()
local itemicon = clone:WaitForChild("Icon", 999)
local text = clone:WaitForChild("Label", 999)
itemicon.Image = "rbxassetid://"..icon.Value
text.Text = tostring(v.Name).." - "..tostring(price.Value).."XP"
clone.Visible = true
clone.Name = tostring(v.Name)
clone.Parent = items
-- Setup Color
local round = clone:WaitForChild("Roundify", 999)
equippedcolor = Color3.fromRGB(55, 255, 95)
ownedcolor = Color3.fromRGB(255, 136, 0)
nilcolor = Color3.fromRGB(231, 231, 231)
hovercolor = Color3.fromRGB(37, 173, 231)
local defaultcolor = nilcolor
-- StartColor
if EquippedItem.Value == clone.Name then
defaultcolor = equippedcolor
elseif OwnedItems:FindFirstChild(clone.Name) then
defaultcolor = ownedcolor
else
defaultcolor = nilcolor
end
-- Set Start Color
round.ImageColor3 = defaultcolor
-- Mouse Control
clone.MouseEnter:Connect(function()
round.ImageColor3 = hovercolor
end)
clone.MouseLeave:Connect(function()
round.ImageColor3 = defaultcolor
end)
clone.MouseButton1Click:Connect(function()
if OwnedItems:FindFirstChild(clone.Name) then
if EquippedItem.Value == clone.Name then
EquippedItem.Value = ""
else
EquippedItem.Value = clone.Name
end
else
local own = Instance.new("BoolValue")
own.Name = clone.Name
own.Parent = OwnedItems
end
end)
OwnedItems.ChildAdded:Connect(function(child)
if child.Name == clone.Name then
defaultcolor = ownedcolor
end
end)
OwnedItems.ChildRemoved:Connect(function(child)
if child.Name == clone.Name then
defaultcolor = nilcolor
end
end)
EquippedItem.Changed:Connect(function()
if EquippedItem.Value == clone.Name then
defaultcolor = equippedcolor
elseif OwnedItems:FindFirstChild(clone.Name) then
defaultcolor = ownedcolor
else
defaultcolor = nilcolor
end
end)
end
end
end
for i, v in pairs(items:GetChildren()) do
if not trails:FindFirstChild(v.Name) and not v:IsA("UIGridLayout") then
v:Destroy()
end
end
end
trails.ChildAdded:Connect(function()
update()
end)
trails.ChildRemoved:Connect(function()
update()
end)
while true do
-- Update
update()
wait(3)
end
The problem is, it creates a list of all the in game trails you can buy with XP for my game. It does that okay but the problem is the Mouse Enter and Mouse Leave is inconsistent. Here's what happens. If the item was already there when I started the game, the item doesn't work. If I add the item in at runtime, the mouse enter / leave works. If I cut on of the items that was there when it started, the mouse enter / leave works. If it stays there and it was there when the game started, it doesn't work. My simple script makes the icon blue when hovered and then back to grey when not hovering. But it's so inconsistent. Why does this happen? I'm guessing it's because something isn't loaded up quite right yet. But what isn't? Have you guys got any ideas I would be extremely grateful to have a fix and an explanation for this.

4 comments
show the full script
You're calling a function, within a function?
I was calling the function within a function as I thought it would be better than cloning a hover script a ridiculous amount of times.
I have posted the fullcode, VerdommeMan.