Constructive Criticism On Animation Choice Gui

This script sets up a animation choice gui with characters that play the animation. Im still learning how to script so if you have any feedback feel free to share on what practices would be better to use in this script for optimization

image

local FrameNum = script.Parent.FrameNum
local replicatedStorage = game:GetService("ReplicatedStorage")
for _, squareup in pairs(replicatedStorage.SquareUps:GetChildren()) do
	FrameNum.Value = FrameNum.Value + 1
	--// Create Template
	local v = replicatedStorage.Template:Clone()
	--// Enter Names
	v.Title.Text = squareup.Name
	v.Name = squareup.Name
	--// Values
	v.AnimNum.Value = FrameNum.Value
	v.Parent = script.Parent
	--// Play Animation
	local animation = Instance.new("Animation")
	animation.AnimationId = "rbxassetid://" .. squareup.Value
	v.World.Npc.Humanoid:LoadAnimation(animation):Play()
	--// Equip
	v.Equip.MouseButton1Down:Connect(function()
		replicatedStorage.Events.SuChange:FireServer(squareup.Name)
	end)
end
--//Equip + Name + Animations
script.Parent.Next.MouseButton1Down:Connect(function()
	FrameNum.Value = FrameNum.Value + 1
end)
script.Parent.Back.MouseButton1Down:Connect(function()
	FrameNum.Value = FrameNum.Value - 1
end)
script.Parent.Close.MouseButton1Down:Connect(function()
	script.Parent.Parent:TweenPosition(UDim2.new(0, 0,-1, 0),"InOut","Sine",1,true)
end)
--// Change Frame
script.Parent.FrameNum:GetPropertyChangedSignal("Value"):Connect(function()
	for _, animnum in pairs(script.Parent:GetDescendants()) do
		if animnum:IsA("ViewportFrame") then
			animnum.Visible = false
		end
		if animnum:IsA("NumberValue") and animnum.Name == "AnimNum" then
			if animnum.Value == FrameNum.Value then
				animnum.Parent.Visible = true
			end
		end
		if FrameNum.Value == 21 then
			FrameNum.Value = 1
		end
		if FrameNum.Value == 0 then
			FrameNum.Value = 20
		end
	end
end)
FrameNum.Value = script.Parent.Default.AnimNum.Value
script.Parent.Default.Visible = true

Hi BigPressureRareBreed! I suggest you should move this to the “Code Review” section of this category as this post doesn’t fit the section of “Scripting Support”. Thanks!

1 Like