Hello! I have a gui setup with multiple buttons. When these buttons are pressed, the item will be removed and the other items will be moved over to fill the gap, sort of like an inventory system. My only problem is that when any of the buttons are pressed a few seconds after starting up the game, roblox instantly crashes. I don't know if this is an issue with the multiple for loops and connections running for each item, or something different. I could use some help!
local hov = require(script.Hov)
game.StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Backpack,false)
local data = game.ReplicatedStorage.Remotes.GetInfo:InvokeServer()
print(data)
for l,d in ipairs(data.Inventory) do
if l <=5 then
game.ReplicatedStorage.PreviewModels[d]:Clone().Parent = script.Parent[tostring(l)].View.WorldModel
script.Parent[tostring(l)].Tooltip.Text = d
script.Parent[tostring(l)].Name = d
end
end
game.Players.PlayerRemoving:Connect(function(plr)
if plr.UserId == game.Players.LocalPlayer.UserId then
local list = {}
for i,v in ipairs(script.Parent:GetChildren()) do
if v:IsA('TextButton') then
if v.Name ~= v.Text then
table.insert(list,v.Name)
end
end
end
game.ReplicatedStorage.Remotes.SaveTowers:FireServer(list)
end
end)
for i,v in ipairs(script.Parent:GetChildren()) do
print(v)
if v:IsA('TextButton') then
print('sup')
local e,l = hov.MouseEnterLeaveEvent(v)
local active = false
e:Connect(function()
v:TweenSize(UDim2.new(0,74,0,74),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.1)
v.Tooltip.Visible = true
end)
l:Connect(function()
if not active then
v:TweenSize(UDim2.new(0,70,0,70),Enum.EasingDirection.Out,Enum.EasingStyle.Quad,0.1)
v.Tooltip.Visible = false
end
end)
v.MouseButton1Click:Connect(function()
v.View.WorldModel:FindFirstChildWhichIsA("Model"):Destroy()
v.Tooltip.Text = "Empty"
v.Name = v.Text
for r,d in ipairs(script.Parent:GetChildren()) do
if d:IsA('TextButton') and tonumber(d.Text) > tonumber(v.Text) and d.Name ~= d.Text then
for p,k in ipairs(script.Parent:GetChildren()) do
if k:IsA('TextButton') and tonumber(k.Text) == tonumber(d.Text)-1 and tonumber(d.Text) ~=1 then
if d.View.WorldModel:FindFirstChildWhichIsA("Model") then
d.View.WorldModel:FindFirstChildWhichIsA("Model").Parent = k.View.WorldModel
k.Tooltip.Text = d.Tooltip.Text
d.Tooltip.Text = "Empty"
end
end
end
end
end
end)
end
end

1 comment
sometimes when a for function goes too fast it does that. it just a guess but try adding a wait() after you started the for function