I’m trying to make a system that equip a tool when it’s on the player storage, but this weird bug has appeared.
BTW: the buttons are clones
My code:
for i, child in pairs(Client.PlayerGui:WaitForChild('StorageUI'):WaitForChild('Background'):WaitForChild('List'):GetDescendants()) do
if child:IsA('TextButton') then -- It print's fine
child.MouseButton1Click:Connect(function() --// This is the problem
print('a')
if ReplicatedStorage.Items:FindFirstChild(child.Name) then
print('hi')
local newitem = ReplicatedStorage.Items:FindFirstChild(child.Name):Clone()
newitem.Parent = Client.Backpack
child:Destroy()
else
print('Not Found: '..child.Name)
end
end)
end
end
This looks like a Server Script, in which case you need to move your code to a LocalScript and have the buttons tell the Server when they are clicked, since MouseButton1Click is not replicated to the Server.
If you run the loop with the function before the buttons are created the function isn’t going to work. Make sure you first insert the buttons and THEN run the loop with the function.
Do it like this:
-Insert the buttons
-Run the for i,v loop with the function