I’m not sure if this is the correct category but I think it has some relation about this bugs/glitch.
So basically I have this TextButton UIS that when clicked it will shows a frame, or we can call it Inventory uis. The errors/glitch I’m encountering is that it cause the game (Client) to freeze a bit or sometimes can be long when i clicked it but the codes are workings properly.
Is there any reason why this is happening and how would i fix it?
-- Activating the GUI
local open = 0
InventoryButton.Activated:Connect(function()
if open == 0 then
open = 1
selectedTower = tower.Name
UpdateSkins()
if tower.InvisibleForever == false then
gui.Inventory.Towers.TowersScroll:FindFirstChild(newButtonTower.ViewportFrame.TowerName.Text).Visible = true
gui.Inventory.Towers.TowersScroll:FindFirstChild(newButtonTower.ViewportFrame.TowerName.Text).Visible = true
end
end
end)
Let me guess, Its because i looped through many things?
for i, skin in pairs(skinshop) do
local oldButton = gui.Inventory.Skins.TowersScroll:FindFirstChild(skin.Name)
if oldButton then
oldButton:Destroy()
end
local clonedTower = game.ReplicatedStorage.Skins[skin.Name]:Clone()
local newButtonTower = gui.Inventory.Skins.TowersScroll.Template:Clone()
newButtonTower.Name = skin.Name
newButtonTower.ViewportFrame.TowerName.Text = skin.Display
newButtonTower.Parent = gui.Inventory.Skins.TowersScroll
newButtonTower.LayoutOrder = skin.Price
newButtonTower.ViewportFrame.TowerName.TextColor3 = skin.RarityColor
clonedTower.Parent = newButtonTower.ViewportFrame.WorldModel
clonedTower.PrimaryPart = clonedTower.HumanoidRootPart
local TowerAnim = clonedTower.Humanoid.Animator:LoadAnimation(clonedTower.Animations.Idle)
TowerAnim:Play()
Hmm I’m still not entirely sure BUT do these things please, Make sure you do all the changes you want to the properties Before you parent these things. For Example, you’re parenting the newButtonTower before you’re setting the LayoutOrder and Setting the TextColor, same for the PrimaryPart for clonedTower. Do that and let me know fi that helped.