The print keeps firing multiple times. If I delete a frame, it doesn’t consider it as a deletion.
It will print all frames that previously existed. It also seems to mess up with the tween service. The tween only works when I click the delete button, but clicking Yes or No does not animate the tween, probably due to multiple connections. How can I fix this?
Relevant part:
print("finished: " .. frame.Name)
local window_SavedOutfits = script.Parent.Parent:WaitForChild("SavedOutfits")
local window_Buttons = script.Parent.Parent:WaitForChild("Buttons")
local window_ConfirmDelete = script.Parent:WaitForChild("ConfirmationDelete")
local confirmDeletionButton = window_ConfirmDelete:WaitForChild("Yes")
local cancelDeletionButton = window_ConfirmDelete:WaitForChild("No")
local loadedOutfitsFrame = {}
local function f_removeOutfitFrame(obj : "Frame/Name")
local frame : Frame = obj
if not obj:IsA("Frame") then
frame = window_SavedOutfits.Container.ScrollingFrame:FindFirstChild(obj)
if not frame then warn("no frame found with outfut name") return false end
end
local success, msg =
pcall (function()
Remotes.RemoveOutfit:InvokeServer(DescriptionConvertor.SerializeHumanoidDescription(frame:FindFirstChildWhichIsA("HumanoidDescription")))
end)
print(msg)
if success then
table.remove(loadedOutfitsFrame, table.find(loadedOutfitsFrame, frame))
frame:Destroy()
end
end
local function f_addOutfitFrame(desc)
local frame = Templates.SavedOutfitTemplate:Clone()
frame.Name = desc.Name
frame.FitName.Text = desc.Name
desc:Clone().Parent = frame
local rigType = desc:GetAttribute("Rig") or "R6"
local rig = Templates:FindFirstChild("Rig"..desc:GetAttribute("Rig")):Clone()
local viewport = frame.ViewportFrame
rig.Parent = workspace
rig:FindFirstChildWhichIsA("Humanoid"):ApplyDescriptionReset(desc)
rig.Parent = viewport.WorldModel
local rigcf = rig.HumanoidRootPart.CFrame
local cam = Instance.new("Camera", viewport)
viewport.CurrentCamera = cam
cam.CFrame = CFrame.new(rigcf.Position+rigcf.LookVector*ZoomOut, rigcf.Position)
cam.FieldOfView = 20
local rigAngle = Instance.new("NumberValue", frame)
rigAngle.Changed:Connect(function()
rig.HumanoidRootPart.CFrame = CFrame.new(rigcf.Position+rigcf.LookVector*rigAngle.Value/90)*CFrame.Angles(0, math.rad(rigAngle.Value), 0)
end)
-- Tweening information
local tTweenInfo = TweenInfo.new(
0.8, -- Time
Enum.EasingStyle.Sine, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (0 = no repeat)
false, -- Reverses (does not reverse back and forth)
0 -- DelayTime
)
local spinTween = srvc_twn:Create(rigAngle, tTweenInfo,
{Value = 320}
)
local unspinTween = srvc_twn:Create(rigAngle, tTweenInfo,
{Value = 0}
)
local frameToDelete = nil
local function showConfirmationWindow(frame)
frameToDelete = frame
window_ConfirmDelete.Visible = true
window_ConfirmDelete.Position = UDim2.new(0.5, 0, 0.75, 0)
local enterTween = tweenGui(window_ConfirmDelete, UDim2.new(0.5, 0, 0.5, 0), 0, 0.3)
enterTween:Play()
end
frame.MouseEnter:Connect(function()
rig.Animate.PlayEmote:Invoke("wave")
spinTween:Play()
end)
frame.MouseLeave:Connect(function()
unspinTween:Play()
end)
frame.DeleteIcon.MouseButton1Click:Connect(function()
showConfirmationWindow(frame)
end)
cancelDeletionButton.MouseButton1Click:Connect(function()
local exitTween = tweenGui(window_ConfirmDelete, UDim2.new(0.5, 0, 1, 0), 0.1, 0.1)
exitTween:Play()
exitTween.Completed:Connect(function()
window_ConfirmDelete.Visible = false
window_ConfirmDelete.Position = UDim2.new(0.5, 0, 0.5, 0)
print("finished: " .. frame.Name)
end)
frameToDelete = nil
end)
confirmDeletionButton.MouseButton1Click:Connect(function()
local exitTween = tweenGui(window_ConfirmDelete, UDim2.new(0.5, 0, 1, 0), 0.1, 0.1)
exitTween:Play()
exitTween.Completed:Connect(function()
window_ConfirmDelete.Visible = false
window_ConfirmDelete.Position = UDim2.new(0.5, 0, 0.5, 0)
end)
if frameToDelete then
f_removeOutfitFrame(frameToDelete)
showSaveMsg:FireServer("You've successfully deleted your outfit!", true, "Success")
frameToDelete = nil
end
end)
frame.Click.MouseButton1Click:Connect(function()
f_morphCharacter(desc)
end)
frame.Parent = window_SavedOutfits.Container.ScrollingFrame
frame.Visible = true
table.insert(loadedOutfitsFrame, frame)
end